Mufid Bagdadi

Mufid Bagdadi

  • NA
  • 146
  • 24.4k

The GridView 'GridView1' fired event...

May 7 2016 2:39 AM
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,
 
 
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
AutoGenerateColumns="false" OnSelectedIndexChanged = "OnSelectedIndexChanged" AllowPaging="true"
PageSize="10" emptydatatext="No data available." >
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<Columns>
<asp:BoundField DataField="transactionid" HeaderText="Transaction ID"
ItemStyle-Width="150" >
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="empCode" HeaderText="Employee Code"
ItemStyle-Width="150" >
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="empName" HeaderText="Employee Name"
ItemStyle-Width="250" >
<ItemStyle Width="200px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="locationApproval" HeaderText="Status"
ItemStyle-Width="150" >
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:ButtonField Text="Select" CommandName="Select" ItemStyle-Width="150" >
<ItemStyle Width="150px"></ItemStyle>
</asp:ButtonField>
</Columns>
</asp:GridView>
 
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");
}
 
 
 

Answers (1)