Set
AutoPostback property of your grid checkbox to true and create selected index changed event of your checkbox and store the selected item in Session. Now when you go to the next page you can refer selected value from session. Find below code sample for the same kind of functionality :
ASPX Code :
<asp:GridView runat="server" ID="gridMain" AutoGenerateColumns="False" OnRowDataBound="gridMainRowDataBound">
<Columns>
<asp:BoundField DataField="EmployeeName" HeaderText="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBoxList runat="server" ID="checkDivisions" AutoPostBack="True" OnSelectedIndexChanged="divisonChanged"/> </ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
ASPX.cs Code :
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
var empList = new List<Employee>();
for (var i = 0; i < 5; i++)
{
var employee = new Employee
{
EmployeeName = "Name_" + i,
Divisions =
new List<Division>
{
new Division
{
DivisionName = "A",
DivisonID = "1"
},
new Division
{
DivisionName = "B",
DivisonID = "2"
},
new Division
{
DivisionName = "C",
DivisonID = "3"
}
}
};
empList.Add(employee);
}
this.gridMain.DataSource = empList;
this.gridMain.DataBind();
}
protected void gridMainRowDataBound(object sender, GridViewRowEventArgs e)
{
var divisonList = e.Row.Cells[1].FindControl("checkDivisions") as CheckBoxList;
if (divisonList != null)
{
divisonList.DataSource = DataBinder.Eval(e.Row.DataItem, "Divisions");
divisonList.DataTextField = "DivisionName";
divisonList.DataValueField = "DivisonID";
divisonList.DataBind();
}
}
protected void divisonChanged(object sender, EventArgs e)
{
Session["LastSelectedItem"] = ((ListControl)sender).SelectedItem.Text;
}
}
public class Employee
{
public string EmployeeName { get; set; }
public List<Division> Divisions { get; set; }
}
public class Division
{
public string DivisionName { get; set; }
public string DivisonID { get; set; }
}