Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone help me to get the value of the CheckBox from the nested grid?

I have the grid inside the grid, in the child grid I have a CheckBox. I am trying to get the value of the CheckBox to insert it into the database, but I am not getting the value.

Please help me to get the value.
ASP.NET
<asp:GridView ID="HeaderCheckGv" runat="server" AutoGenerateColumns="False" OnRowDataBound="HeaderCheckGv_RowDataBound">
                    <columns>
                        <asp:BoundField DataField="POLICY_MAIN_ID" />
                        <asp:BoundField DataField="POLICY_ID"  />
                        <asp:BoundField DataField="POLICY_VALUE"  />
                        <asp:TemplateField >
                            <itemtemplate>
                                <asp:Label ID="GroupNameLbl" runat="server" Text='<%# Eval("POLICY_NAME")%>'>
                                <asp:GridView ID="ChildCheckGv" runat="server" AutoGenerateColumns="False" OnRowDataBound="ChildCheckGv_RowDataBound">
                                    <columns>
                                        <asp:BoundField DataField="POLICY_MAIN_ID"  />
                                        <asp:BoundField DataField="POLICY_ID" />
                                        <asp:BoundField DataField="POLICY_NAME" />
                                        <asp:TemplateField HeaderText="GeneralPolicy">
                                        <itemtemplate>
                                                <asp:CheckBox ID="GeneralPolicyCb" runat="server" />
</itemtemplate>
                                    </columns>
                            </itemtemplate>
                    </columns>
                </columns></itemtemplate></columns>
Posted
Updated 3-Mar-12 20:56pm
v2
Comments
André Kraak 4-Mar-12 2:56am    
Edited question:
Added pre tags
Formatted text/code

1 solution

try this:-
private void HeaderCheckGv_RowDataBound(object sender,
  GridViewRowEventArgs e)
{
  if(e.Row.RowType == DataControlRowType.DataRow)
  {
    //Finding the Grid Control First
    GridView grdChildGrid=(GridView)e.Row.FindControl("ChildCheckGv");
    
   //From the object of founded Child Grid Control we can easily get the controls  value in the child grid like this
     CheckBox chkBox=(CheckBox)grdChildGrid.Row.FindControl("ChildCheckGv");
     bool chkValue = Convert.ToBoolean(chkBox.Value);
  }
}


I hope this will help you out. Please don't forget to mark this as your answer :)
 
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