如何检查嵌套Datagrid中单击的行按钮 [英] how to check which row button is clicked inside Nested Datagrid
问题描述
我正在开发一个Web应用程序,其中包含一个嵌套有另一个数据网格的数据网格。其中,子数据网格在每个父网格的末尾都包含一个按钮,如下所示:-
I was Developing an Web application which contains a Data Grid nested with another Data Grid.Where as the Child Data Grid Contains a Button At the End of Each Parent Grid as Shown below:-
我想要在按钮上知道的是单击单击哪个按钮。
What i want is I need to know on Button Click Which Button is clicked.
这是我的aspx代码:
Here is my aspx code:
<asp:DataGrid ID="dgparent" runat="server" BorderWidth="1px" BorderColor="#FE9B00">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DataGrid ID="dgchild" runat="server" >
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="mFCF_NUPKId" Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="CostSheetNo" HeaderText="CostSheetNo" SortExpression="CostSheetNo">
</Columns>
</asp:DataGrid>
<table>
<tr>
<td>
<asp:Label ID="LblTotalCoLoaderFrom1" runat="server" Text="Total Cost : "></asp:Label>
<asp:TextBox ID="TxtTotalCoLoaderFrom1" runat="server" Enabled="false"></asp:TextBox>
</td>
<td>
<asp:Label ID="LblTotalYeild" runat="server" Text="Total Yeild : "></asp:Label>
<asp:TextBox ID="TxtTotalYeild" runat="server" Enabled="false"></asp:TextBox>
</td>
<td>
<asp:Button ID="BTNBookingReq" runat="server" class="formbutton" OnClick="BTNBookingReq_Click" Text="Send Booking Request"/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
这是我的C#:
protected void BTNBookingReq_Click(Object sender, EventArgs e)
{
Button btnSender = (Button)sender;
//if(btnSender == 1strow)
//Need to get the Parent Column Text
else if(btnSender == 2ndrow)
//Need to get the Parent Column Text
.........
}
可以一个请帮助我解决这个问题。
提前致谢
can any one please help me to solve this issue. Thanks in Advance
推荐答案
您可以使用按钮的NamingContainer获取父网格项,这将为数据网格项目。在这里您可以使用FindControl方法找到每个文本框,如下所示:
You can get the parent grid item using NamingContainer of the button, which will give the datagrid item. From there you can find each textbox using the FindControl method as below
protected void BTNBookingReq_Click(Object sender, EventArgs e)
{
Button btnSender = (Button)sender;
DataGridItem item = btnSender.NamingContainer as DataGridItem;
if (item != null)
{
TextBox TxtTotalCoLoaderFrom1 = item.FindControl("TxtTotalCoLoaderFrom1") as TextBox;
//Do your operation here
}
}
这篇关于如何检查嵌套Datagrid中单击的行按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!