0

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:- enter image description here

What i want is I need to know on Button Click Which Button is clicked.

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>

and this is my 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

0

1 Answer 1

1

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
    }

}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks alot your solution helps me to get out form my rid.
hedge ca u please help me to solve this issue stackoverflow.com/questions/26465071/…
please help me to solve the issue which i mentione here stackoverflow.com/questions/28229164/…
hi can u pls help me to solve the issue in stackoverflow.com/questions/28694509/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.