Friends,
I enable paging and use following event
protected void gvReprintEmail_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvReprintEmail.PageIndex = e.NewPageIndex;
DataTable dt1 = (DataTable)Session["dt"];
gvReprintEmail.DataSource = dt1;
gvReprintEmail.DataBind();
}
But when i want to get any value from gridview then i got exception because in rowcommand event i get value of row from current event. So there is exception like "Index was out of range. Must be non-negative and less than the size of the collection."
I use page size 3 and in 2nd and afterward pages i got exception like this.
here is one of column of gridview
<itemtemplate>
<asp:Label runat="server" ID="lblMessage" Text='<%# Server.HtmlDecode(Eval("Body").ToString()) %>' >
following is rowcommand event where i got exception
in first page there is no problem in this, but afterwards page when i click link given in gridview then there will exception
protected void gvReprintEmail_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument); <--on 2nd page first row i click so index will be 3 because page size 3
Label lbl = (Label)gvReprintEmail.Rows[index].FindControl("lblMessage"); <--exception
Session["SentDate"] = gvReprintEmail.Rows[index].Cells[0].Text;
Session["Subject"] = gvReprintEmail.Rows[index].Cells[1].Text;
Session["Message"] = lbl.Text;
OpenNewWindow("PrintEmail.aspx");
}
Kindly help me. Thanks in advance.