如何从嵌套网格中获取复选框的值 [英] how to get value of checkbox from nested grid

查看:58
本文介绍了如何从嵌套网格中获取复选框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我从嵌套网格中获取CheckBox的值吗?

我在网格内部有网格,在子网格中我有一个CheckBox.我正在尝试获取CheckBox的值以将其插入数据库中,但是我没有获取该值.

请帮助我获得价值.

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: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>

推荐答案

尝试一下:-
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 :)


这篇关于如何从嵌套网格中获取复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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