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

时间:2023-02-07 10:04:20

GridView Page1 CodeBehinde1:

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

Session["customs_Clearance"] = Customs_Clearance;

And Page2 Which Show session GridView Data Code Behind: CheckBox

和Page2哪个Show会话GridView数据代码背后:CheckBox

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

1 个解决方案

#1


0  

Use the code below for your case. I am assuming that the the column with index 23 is the boolean column and displayed as a checkbox column.

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

You can then always access in your other page Session["customs_Clearance"].

然后,您可以随时访问其他页面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");
   }
}

#1


0  

Use the code below for your case. I am assuming that the the column with index 23 is the boolean column and displayed as a checkbox column.

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

You can then always access in your other page Session["customs_Clearance"].

然后,您可以随时访问其他页面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");
   }
}