I have a Gridview with paging enabled and checkBox, with Columns UserName, etc. On ButtonClick event I want to save the UserName to Database for selected checkbox. I am unable to get the UserName for the selected checkbox and stuck. Help appriciated.
protected void BtnSaveAuthorization_Click(object sender, EventArgs e)
{
}
protected void GVRegisterNewCarton_PageChanging(object sender, GridViewPageEventArgs e)
{
string pageId = string.Format("Page{0}", GVRegisterNewCarton.PageIndex);
bool[] selectedCheckboxes = new bool[GVRegisterNewCarton.PageSize];
for (int i = 0; i < GVRegisterNewCarton.Rows.Count; i++)
{
TableCell cell = GVRegisterNewCarton.Rows[i].Cells[0];
selectedCheckboxes[i] = (cell.FindControl("chkSelectAdd") as CheckBox).Checked;
}
ViewState[pageId] = selectedCheckboxes;
GVRegisterNewCarton.PageIndex = e.NewPageIndex;
BindData();
//Bind the gridview again
}
protected void GVRegisterNewCarton_PreRender(object sender, EventArgs e)
{
string pageId = string.Format("Page{0}", GVRegisterNewCarton.PageIndex);
bool[] selectedCheckboxes = ViewState[pageId] as bool[];
if (selectedCheckboxes != null)
{
for (int i = 0; i < GVRegisterNewCarton.Rows.Count; i++)
{
TableCell cell = GVRegisterNewCarton.Rows[i].Cells[0];
(cell.FindControl("chkSelectAdd") as CheckBox).Checked = selectedCheckboxes[i];
}
}
}
Aucun commentaire:
Enregistrer un commentaire