2014-09-24 38 views
0

我開發包含一個數據網格嵌套另一個數據Grid.Where作爲子數據網格包含一個按鈕在每個父格柵端部,如下圖所示的Web應用程序: - enter image description here如何檢查這排按鈕被點擊嵌套DataGrid中

我想要的是我需要知道的按鈕點擊哪個按鈕被點擊。

這裏是我的aspx代碼:

<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 
      ......... 
     } 

任何一個可以請幫我解決這個問題。 預先感謝

回答

1

您可以使用按鈕的NamingContainer獲取父網格項目,該項目將提供datagrid項目。從那裏你可以找到每個文本框使用下面的FindControl方法

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 
    } 

} 
+0

非常感謝您的解決方案幫助我擺脫我的擺脫。 – Appdev 2014-09-26 09:59:57

+0

對衝CAü請幫我解決這個問題http://stackoverflow.com/questions/26465071/how-to-upload-the-file-using-neatupload – Appdev 2014-10-20 11:55:36

+0

請幫我解決我這裏mentione HTTP的問題: //stackoverflow.com/questions/28229164/web-application-which-is-working-in-firefox-chrome-and-ie8-is-not-opening-in-ie1 – Appdev 2015-01-30 05:17:27

相關問題