Click here to Skip to main content
15,997,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to show a Master/Child data in a page and I have used multiple GridViews to achieve the same. So, I have created two GridViews (Parent & Child) and now I want to fire the Button click event (i.e. btnLock) from the child gridview control and do some DB operations. So, I dont know how to achieve this.

Please help.

ASP.NET
<asp:UpdatePanel ID="pnlUpdate" runat="server">
<contenttemplate>
<asp:GridView Width="100%" AllowPaging="True" ID="gvCustomers" AutoGenerateColumns="False"
DataSourceID="sqlDsCustomers" runat="server" ShowHeader="False" OnRowCreated="gvCustomers_RowCreated">
<columns>
<asp:TemplateField>
<itemtemplate>

    <div class="group" id="<%#String.Format("customer{0}",Container.DataItemIndex) %>" önclick="showhide(<%#String.Format("\"#customer{0}\"",Container.DataItemIndex) %>,<%#String.Format("\"#order{0}\"",Container.DataItemIndex) %>)">
        <asp:Image ID="imgCollapsible" CssClass="first" ImageUrl="~/Assets/img/plus.png"
            Style="margin-right: 5px;" runat="server" />
                <%#Eval("CustomerID")%>
                :
                <%#Eval("CompanyName")%>
                (<%#Eval("TotalOrders")%>
                Orders) 
    </div>
    <asp:SqlDataSource ID="sqlDsOrders" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>"
        SelectCommand="SELECT [OrderID], [OrderDate], [RequiredDate], [Freight], [ShippedDate] FROM [Orders] WHERE ([CustomerID] = @CustomerID)">
        <SelectParameters>
            <asp:Parameter Name="CustomerID" Type="String" DefaultValue="" />
        </SelectParameters>
    
    <div id="<%#String.Format("order{0}",Container.DataItemIndex) %>" class="order">
        <asp:GridView AutoGenerateColumns="false" CssClass="grid" ID="gvOrders" DataSourceID="sqlDsOrders"
            runat="server" ShowHeader="true" EnableViewState="false">
            <rowstyle cssclass="row" />
            <alternatingrowstyle cssclass="altrow" />
            <columns>
                <asp:TemplateField ItemStyle-CssClass="rownum">
                    <itemtemplate>
                        <%# Container.DataItemIndex + 1 %>
                    </itemtemplate>
                
                <asp:BoundField HeaderText="Order ID" DataField="OrderID" ItemStyle-Width="80px" />
                <asp:BoundField HeaderText="Date Ordered" DataField="OrderDate" DataFormatString="{0:MM/dd/yyyy}"
                    ItemStyle-Width="100px" />
                <asp:BoundField HeaderText="Date Required" DataField="RequiredDate" DataFormatString="{0:MM/dd/yyyy}"
                    ItemStyle-Width="110px" />
                <asp:BoundField HeaderText="Freight" DataField="Freight" DataFormatString="{0:c}"
                    ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Right" />
                <asp:BoundField HeaderText="Date Shipped" DataField="ShippedDate" DataFormatString="{0:MM/dd/yyyy}"
                    ItemStyle-Width="100px" />
                    <asp:TemplateField>
                        <itemtemplate>
                            <asp:Button ID="btnLock" Text="Lock" CommandName="Lock" CommandArgument=<%# Eval("OrderID") %> runat="server" />
                        </itemtemplate>    
                    
            </columns>
        
    </div>
</itemtemplate>

</columns>

</contenttemplate>


Thanks in advance.
Posted

1 solution

Hi Ragasai,

Go to design mode of your aspx page and then click on edit item templates of parent gridview and drilldown until you find your child grid and then click on edit item templates of child gridview and select btnLock and raise event.


Hope this helps,

Best Regards,
Sriman
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900