I have created a gridview in my web application but when i try to go to next page of grid view it gives an error, I am trying to fetch data from database through c# code.
following is the exception...
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
gridview asp Code,
AutoGenerateColumns="false" OnSelectedIndexChanged = "OnSelectedIndexChanged" AllowPaging="true"
PageSize="10" emptydatatext="No data available." >
ItemStyle-Width="150" >
ItemStyle-Width="150" >
ItemStyle-Width="250" >
ItemStyle-Width="150" >
C# code:
protected void quality_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
head.Text = "Following are the employee code who had applied for 'Quality (Sigma - The mark of Quality)' award.";
head.Visible = true;
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
string sql = null;
string connetionString = WebConfigurationManager.ConnectionStrings["umangDatabase"].ConnectionString;
sql = "select transactionid, empcode, empname, locationApproval from appData where awardtype='Quality (Sigma- The mark of the Quality)' and location='API_Thane'";
SqlConnection connection = new SqlConnection(connetionString);
connection.Open();
SqlCommand command = new SqlCommand(sql, connection);
adapter.SelectCommand = command;
adapter.Fill(ds);
adapter.Dispose();
command.Dispose();
connection.Close();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "Transaction ID";
e.Row.Cells[1].Text = "Empoyee Name";
e.Row.Cells[2].Text = "Empoyee Code";
e.Row.Cells[3].Text = "Status";
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.backgroundColor='#9A3334';";
e.Row.Attributes["onmouseout"] = "this.style.backgroundColor='white';";
e.Row.ToolTip = "Click last column for selecting this row.";
}
}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
//Accessing BoundField Column
string transID = GridView1.SelectedRow.Cells[0].Text;
Session["employee"] = transID;
Response.Redirect("print.aspx");
}
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsForums
Top experts
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Raja TRank #685 · 3.5K reputationPosted May 7, 2016, 12:26 AM EDT