Hi friends,
I am entering children details like sr no, child name and age in a gridview. There is a button called ADD NEW in a footer. When I click on the button the new empty row gets added. I have set the allowpaging property to true and called the function on pageindexchanging. But when I go on second page and again come back on first all the data gets vanishes and empty row remains. Here I have set the page size to 5.
Any help would be appreciated
Thanks,
Vijay
Loading


Blocked AccountRank #403 · 6.2K reputationPosted Jan 20, 2011, 1:05 AM EST
I think you are not binding the gridview in PageIndexchanging event.
try this
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Jan 20, 2011, 1:08 AM EST
Is your problem solved? send me the code if not.
Vijay YadavRank #1,637 · 943 reputationPosted Jan 20, 2011, 1:14 AM EST
@Manish i have binded that function but still it is not getting done and
@Jitendra not solved yet, if you know please tell me..
Thanks,
Vijay
Blocked AccountRank #403 · 6.2K reputationPosted Jan 20, 2011, 1:17 AM EST
Can you post your code here. It would be fine to solve your problem.
Vijay YadavRank #1,637 · 943 reputationPosted Jan 20, 2011, 1:56 AM EST
public void children()
{
int num = 0;
dt = new DataTable();
dt.Columns.Add("SR_NO", typeof(string));
dt.Columns.Add("EMPLOYEE_CODE", typeof(string));
dt.Columns.Add("EMPLOYEE_NAME", typeof(string));
dt.Columns.Add("CHILD_NAME", typeof(string));
dt.Columns.Add("CHILD_AGE", typeof(string));
foreach (GridViewRow row in grvChildrenDetails.Rows)
{
DataRow dr;
dr = dt.NewRow();
dr["SR_NO"] = ((Label)row.FindControl("lblsr_no")).Text;
dr["CHILD_NAME"] = ((TextBox)row.FindControl("txtchildname")).Text;
dr["CHILD_AGE"] = ((TextBox)row.FindControl("txtchildage")).Text;
num =Convert.ToInt32(dr["SR_NO"]);
dt.Rows.Add(dr);
}
// dt = (DataTable)grvChildrenDetails.DataSource;
if (num > 4)
{
}
else
{
DataRow dr1 = dt.NewRow();
dt.Rows.Add(dr1);
//DataView dv = dt.DefaultView;
grvChildrenDetails.DataSource = dt;
grvChildrenDetails.DataBind();
}
}
this function i call on button click in footer to add new row
and on page index changing..
protected void grvChildrenDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grvChildrenDetails.PageIndex = e.NewPageIndex;
children();// same function which i call on button click..
}
Any help would be appreciated.
Thanks,
Vijay
vijay172 reputationPosted Jan 20, 2011, 7:38 PM EST
for page index changing try this code it really helpful to you.....
Protected Sub grdRemittance_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdRemittance.PageIndexChanging
grdRemittance.PageIndex = e.NewPageIndex
grdRemittance.DataBind()
End Sub
regards vijay
http://vbdotnetaddict.blogspot.com
Vijay YadavRank #1,637 · 943 reputationPosted Jan 20, 2011, 7:47 PM EST
I had tried this but it clears the gridview anyway..
Thanks,
Vijay
Suthish NairRank #92 · 22.8K reputationPosted Jan 21, 2011, 9:35 AM EST
Vijay YadavRank #1,637 · 943 reputationPosted Jan 23, 2011, 6:56 PM EST
I have used it... but then also its not working..
Thanks,
vijay
Michael Xie16 reputationPosted Feb 12, 2011, 9:09 AM EST
Suthish NairRank #92 · 22.8K reputationPosted Feb 12, 2011, 9:24 AM EST
Or, use UpdatePanel might works.
Or, do not allow user to do paging during edit mode.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.pageindexchanging.aspx