简体   繁体   English

从Gridview获取所有检查的隐藏值

[英]Get all checked hidden values from Gridview

I have a gridview with checkbox. 我有一个带有复选框的gridview。 When some one selects checkboxes i want get all checked hidden values and save into database.Below is my grid. 当有人选择复选框时,我想获取所有选中的隐藏值并保存到数据库中。以下是我的网格。

<asp:GridView ID="grdBillableAssetDetails" AutoGenerateColumns="False" runat="server" Width="100%" DataKeyNames="ListId">
    <HeaderStyle CssClass="GridHeader" />                                    
    <RowStyle BackColor="White" ForeColor="#284775" CssClass="GridRow" Height="25px" />                          
    <Columns>
        <asp:TemplateField HeaderText="Check AssetSubType" SortExpression="CheckAssetSubType">
            <ItemStyle HorizontalAlign="Center" Width="100px" />
            <ItemTemplate>
                <asp:CheckBox ID="chkAssetSubType" runat="server" Checked='<%#Eval("Select").ToString() == "1" ? true:false%>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="ListId" HeaderText="ListId" Visible="false">
            <HeaderStyle HorizontalAlign="Center" Width="150px" /> 
            <ItemStyle HorizontalAlign="center" Width="150px" />
        </asp:BoundField>
        <asp:BoundField DataField="AssetType" HeaderText="AssetType">
            <HeaderStyle HorizontalAlign="Center" Width="150px" /> 
            <ItemStyle HorizontalAlign="center" Width="150px" />
        </asp:BoundField>
        <asp:BoundField DataField="AssetSubType" HeaderText="AssetSubType">
            <HeaderStyle HorizontalAlign="Center" Width="150px" /> 
            <ItemStyle HorizontalAlign="center" Width="150px" />
        </asp:BoundField>
    </Columns>
</asp:GridView>

Below is my Code behind i want store list values and CompanyId into database. 下面是我想要将列表值和CompanyId存储到数据库中的代码。

protected void btnSave_ServerClick(object sender, EventArgs e)
{
    try
    {
        int companyId = Convert.ToInt32(Request.QueryString["EntityId"]);
        List<int> listListId = new List<int>();

        foreach (GridViewRow gvrow in grdBillableAssetDetails.Rows)
        {                              
            CheckBox chk = (CheckBox)gvrow.FindControl("chkAssetSubType");
            if (chk.Checked)
            {                   
                int ListId = (int)grdBillableAssetDetails.DataKeys[gvrow.RowIndex].Value;
                listListId.Add(ListId);
            }
        }

        DataAccess.SaveListTypes(companyId, listListId);        

        hdnPageStatus.Value = "0";
    }
    catch (Exception ex)
    {
        hdnErrMsg.Value = ex.Message;
    }
}

Can any please help me. 有什么可以帮助我的吗?

Below an example vb.NET 下面是一个示例vb.NET

For j = 0 To gridCallfile.Rows.Count - 2<br>
    If Convert.ToBoolean (grid.Rows(j).Cells(5).Value) Then<br>
    'your code here
end If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM