Yes it is a button click event that triggers the code. When I do check even the GridView columns count it is 0 so I'm losing the data. The confusing part though is that this code worked in asp.net 1.1. The only difference is that I'm using AJAX (http://ajax.asp.net/).
I can't call DataBind() because I have text boxes that are edited and I want to check the user's input first (ensure only numbers entered) and then save the items to a DataTable as shown below:
I'm not using the ObjectDataSource or SQLDataSource because I'm inheriting this project and I'm thinking it would be a bigger project to change the code rather than just modifying the existing code.
Bill_N
Member
38 Points
23 Posts
Re: datagrid.Items.Count to GridView.Rows.Count
Jun 25, 2007 02:31 PM|LINK
Thanks for the reply.
Yes it is a button click event that triggers the code. When I do check even the GridView columns count it is 0 so I'm losing the data. The confusing part though is that this code worked in asp.net 1.1. The only difference is that I'm using AJAX (http://ajax.asp.net/).
I can't call DataBind() because I have text boxes that are edited and I want to check the user's input first (ensure only numbers entered) and then save the items to a DataTable as shown below:
public DataTable getUpdatedDatagrid(GridView grid,DataTable dt1,int userId) { try { //Loop through GridView Items foreach (GridViewRow grdRow in grid.Rows) { TextBox txt_Day = (TextBox)(grdRow.FindControl("txtDay")); TextBox txt_PremiseID = (TextBox)(grdRow.FindControl("txtPremiseID")); TextBox txt_M1 = (TextBox)(grdRow.FindControl("txtM1")); DataRow dr = dt1.NewRow(); dr[0] = userId; dr[1] = Convert.ToInt32(txt_Day.Text.Trim()); dr[2] = Convert.ToDecimal(txt_PremiseID.Text.Trim()); dr[3] = Convert.ToDecimal(txt_M1.Text.Trim()); dt1.Rows.Add(dr); } } catch (Exception ex) { Session["CurrentError"] = ex.Message; Server.Transfer("Errorpage.aspx"); } return dt1; }I'm not using the ObjectDataSource or SQLDataSource because I'm inheriting this project and I'm thinking it would be a bigger project to change the code rather than just modifying the existing code.
Any help would be greatly appreciated.
Thanks, Bill N