hi,
I have an grid view displaying 5 rows per page. Also i have an button to add an extra row, if user wants.
My problem is While i change the page number to current page to next page i can't access the row in next page. Actually i use foreach() loop to access all rows in the grid. but while i run this loop it can't find the row index "5" which was in second page. It throws an error like "Object reference NULL".
My code is...
protected void Grid_Purchase_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
Grid_Purchase.PageIndex = e.NewPageIndex;
Grid_Purchase.DataSource = Fill();
Grid_Purchase.DataBind();
}
My fill() call....
public DataTable Fill()
{
DataTable dt = new DataTable("items");
dt.Columns.Add("sno", typeof(int));
dt.Columns.Add("Prod_id", typeof(string));
dt.Columns.Add("Prod_name", typeof(string));
dt.Columns.Add("Prod_size", typeof(string));
dt.Columns.Add("Prod_qty", typeof(string));
dt.Columns.Add("Prod_Per_amt", typeof(string));
dt.Columns.Add("Prod_amt", typeof(string));
for (int i = 0; i < totalnumberofrowsin_Grid;i++ )
{
DataRow dr = dt.NewRow();
System.Web.UI.WebControls.TextBox txt_Prodid = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_Pid"));
System.Web.UI.WebControls.DropDownList txt_Prodname = (System.Web.UI.WebControls.DropDownList)(Grid_Purchase.Rows[i].FindControl("txt_grd_ProdName"));
System.Web.UI.WebControls.TextBox txt_Prodsize = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_size"));
System.Web.UI.WebControls.TextBox txt_Prodqty = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_qty"));
System.Web.UI.WebControls.TextBox txt_Prodperamt = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_piece_amt"));
System.Web.UI.WebControls.TextBox txt_Prodamt = (System.Web.UI.WebControls.TextBox)(Grid_Purchase.Rows[i].FindControl("txt_grd_amt"));
dr[0] = i + 1;
dr[1] = txt_Prodid.Text.ToString();
dr[2] = txt_Prodname.Text.ToString();
dr[3] = txt_Prodsize.Text.ToString();
dr[4] = txt_Prodqty.Text.ToString();
dr[5] = txt_Prodperamt.Text.ToString();
dr[6] = txt_Prodamt.Text.ToString();
dt.Rows.Add(dr);
}
return dt;
}
Please give me your suggestions.