vendredi 26 décembre 2014

Issue saving gridview checkbox checked items from multiple pages while paging

I have an issue saving gridview checkbox checked items values while paging. I am unable to retrieve the value items for which checkbox is checked. Appriciate any help in this regard



protected void BtnSaveAuthorization_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
try {

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++)
{

string UserName = ((Label)GVRegisterNewCarton.Rows[i].FindControl("UserName")).Text;

string DeptCode = ((Label)GVRegisterNewCarton.Rows[i].FindControl("DeptCode")).Text;

const string SQLFilePermoutDelivery = "INSERT INTO Test1(UserName, DeptCode) VALUES(@UserName, @DeptCode)";

SqlCommand cmdFilePermoutDelivery = new SqlCommand(SQLFilePermoutDelivery, con1);
cmdFilePermoutDelivery.Parameters.Add("@UserName", SqlDbType.VarChar);
cmdFilePermoutDelivery.Parameters["@UserName"].Value = UserName;
cmdFilePermoutDelivery.Parameters.Add("@DeptCode", SqlDbType.VarChar);
cmdFilePermoutDelivery.Parameters["@DeptCode"].Value = DeptCode;
con1.Open();
cmdFilePermoutDelivery.ExecuteNonQuery();
con1.Close();


BindData();

}
}

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Success');", true);

BindData();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);

}


}





Aucun commentaire:

Enregistrer un commentaire