嵌套的GridView-如何触发子GridView Button单击事件 [英] Nested GridView - How to trigger the Child GridView Button Click event

查看:100
本文介绍了嵌套的GridView-如何触发子GridView Button单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在页面中显示主数据/子数据,并且我使用了多个GridView来实现相同的目的.因此,我创建了两个GridView(父级和子级),现在我想从子级Gridview控件中触发Button单击事件(即btnLock),并执行一些数据库操作.所以,我不知道该怎么实现.

请帮忙.

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: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" /><span class="header">
                <%#Eval("CustomerID")%>
                :
                <%#Eval("CompanyName")%>
                (<%#Eval("TotalOrders")%>
                Orders) </span>
    </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.

推荐答案

ConnectionStrings:Northwind%>" SelectCommand =" 从[Orders] WHERE([CustomerID] = @CustomerID)中选择[OrderID],[OrderDate],[RequiredDate],[Freight],[ShippedDate]" < SelectParameters > < asp:Parameter 名称 =" 类型 字符串" DefaultValue " / < /SelectParameters > < div =" <%#String.Format(" ,Container.DataItemIndex)%> " 顺序" < asp:GridView AutoGenerateColumns =" CssClass 网格" ID gvOrders" DataSourceID sqlDsOrders" =" 服务器" ShowHeader =" =" false" > < 样式 cssclass =" 行" / > < alternatingrow 样式 cssclass =" altrow" / > < > < asp:TemplateField ItemStyle-CssClass =" > < itemtemplate > <%#Container.DataItemIndex + 1 %> < /itemtemplate > < asp:BoundField HeaderText =" DataField OrderID" ItemStyle-Width 80px" / > < asp:BoundField HeaderText =" DataField OrderDate" DataFormatString {0:MM/dd/yyyy}" span> ItemStyle-Width =" / > < asp:BoundField HeaderText =" DataField RequiredDate" DataFormatString {0:MM/dd/yyyy}" ItemStyle-Width =" / > < asp:BoundField HeaderText =" DataField 运费" DataFormatString {0:c}" span> ItemStyle-Width =" ItemStyle-Horizo​​ntalAlign =" 右" / > < asp:BoundField HeaderText =" DataField ShippedDate" DataFormatString {0:MM/dd/yyyy}" span> ItemStyle-Width =" / > < asp:TemplateField > < itemtemplate > < asp:Button ID =" 文本 锁定" CommandName=" Lock" CommandArgument=<%# Eval( "OrderID") %> runat="server"/> ; < /itemtemplate > < /列 > < /div > < /itemtemplate > < /列 > < /contenttemplate >
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.



Thanks in advance.


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.


希望这会有所帮助,

最好的问候,
Sriman
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


这篇关于嵌套的GridView-如何触发子GridView Button单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆