如何将 Gridview 布尔值存储在会话变量中,并在 asp.net 中显示另一个页面



GridView Page1 CodeBehinde1:

protected void  GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    bool Customs_Clearance = GridView1.SelectedRow.Cells[23].Text;
}
Session["customs_Clearance"] = Customs_Clearance;

第 2 页显示会话 GridView 数据代码隐藏:复选框

CheckCustomClearance.Text=Session ["customs_Clearance"].ToString();

根据您的情况使用以下代码。我假设索引为 23 的列是布尔列并显示为复选框列。

然后,您可以随时在其他页面Session["customs_Clearance"]中访问。

protected void  GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
   //get selected row
   GridRow  selectedRow = GridView1.Rows[GridView1.SelectedIndex];
   //check if it's a checkbox column and set Session variable, if it is
   if(selectedRow.Cells[23].Controls[0] is CheckBox) {
     bool isChecked = (selectedRow.Cells[23].Controls[0] as CheckBox).Checked;
     Session["customs_Clearance"] = (isChecked == true ? "checked" : "unchecked");
   }
}

相关内容

最新更新