R – gridview whith dropdown extender

ajaxasp.netgridview

I have gridview with TextBox Template field and DropDownExtender so when user click on the textbox another gridview will appear tha contain List of items and button to add the item to the first gridview. my qusetion is:
how can i in the event of button click(which is in the extender gridview) to get the row index of the first gridview(which contain the textbox)?

thanks

        <cc1:DropDownExtender ID="uxItemExtender" runat="server" DropDownControlID="uxItemContainer" TargetControlID="uxItems"></cc1:DropDownExtender>
        <asp:Panel BackColor="AliceBlue" ID="uxItemContainer" runat="server" ScrollBars="Both" Height="400" Width="200">
        <asp:GridView ID="uxItemsView" runat="server" Font-Size="Small" AutoGenerateColumns="false" OnRowDataBound="uxItemsView_RowDataBound">
        <Columns>
        <asp:TemplateField HeaderText="Item Details">
        <ItemTemplate>
         <asp:Label ID="uxItemNameLbl" Text="Name :" runat="server"></asp:Label>
        <asp:Label ID="uxItemName" runat="server"></asp:Label><br />
        <asp:Label ID="uxItemDescriptionLbl" Text="Description :" runat="server"></asp:Label>
        <asp:Label ID="uxItemDescription" runat="server"></asp:Label><br />
        <asp:Label ID="uxItemPriceLbl" Text="Price :" runat="server"></asp:Label>
        <asp:Label ID="uxItemPrice" runat="server"></asp:Label><br />
        <asp:Button ID="uxSelectItem" runat="server" Text="Add Item" OnClick="uxSelectItem_Click" /><br />
        </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Picture">
        <ItemTemplate>
        <asp:Image ID="uxItemImage" runat="server" Width="45" Height="50" />
        </ItemTemplate>
        </asp:TemplateField>
        </Columns>
        </asp:GridView>
        </asp:Panel>
         </asp:TemplateField>

Best Answer

I assume you want the row index so that you can find the TextBox and update it.

If that's the case, why not put the inner GridView in the EditItemTemplate instead? That way, you can use the EditIndex property of the external GridView to find the correct row and update the TextBox.

Or, if the secondary GridView is just to display data, consider using a ListBox instead - that way, you won't be inside another Template, and you can just use FindControl.

Related Topic