繁体   English   中英

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

[英]how to store Gridview Boolean value in session variable and show another page in asp.net

GridView第1页CodeBehinde1:

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

Session["customs_Clearance"] = Customs_Clearance;

和显示会话GridView数据代码背后的Page2: 复选框

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");
   }
}

暂无
暂无

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

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