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 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Raja TPosted May 7, 2016, 4:26 AM