0
我有一個帶有複選框的gridview。當有人選中複選框時,我想讓所有選中的隱藏值保存到數據庫中。下面是我的網格。從Gridview獲取所有選中的隱藏值
<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>
下面是我的代碼後面我想存儲列表值和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;
}
}
任何請幫助我。
我希望得到遏制排隱藏值和所有檢查的值存儲到數據庫中。 –
請將您的代碼隱藏(C#或VB.NET)發佈到您試圖獲取所有選中值的地方。 –