are you sure that you have something in that session variable?
you should ALWAYS check this, meaning:
TextBox asdf = ......
if (Session["req_name"] != null)
{
asdf.Text = Session["req_name"].ToString(); // put a breakpoint here and see if the session variable is populated
}
also i noticed this
Please post your code for us to help!!
Mark Answered if it helps - Good luck!
Cheers!
Design And Align - Rob
hi, one thing you should understood that the edit template control will be rendered only after setting grid.EditIndex=e.NewEditIndex and Grid.DataBind(); i.e do like below
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex=e.NewEditIndex;
GridView1.DataSource=ds;
GridView1.DataBind(); // you should rebind the grid to set EditIndex
TextBox asdf = ((TextBox)GridView1.Rows[e.NewEditIndex].FindControl("TextBox1"));
asdf.Text = Session["req_name"] ==null? "": Session["req_name"].ToString();
}
I am not binding to a dataset. I am using a sqldatasource:
SqlDataSource1.SelectCommand = "SELECT * FROM [ADCleanUpData] WHERE (LANID like '%" + TextBox1.Text + "%' or DisplayName like '%" + TextBox1.Text + "%') and ProjectID="+TextBox2.Text+"";
SqlDataSource1.DataBind();
ashiqf
Participant
868 Points
397 Posts
How to Assign a Value to Gridview Cell on the Row Editing event
May 03, 2012 12:37 PM|LINK
Hi All,
I have the below to assign a value to cell in gridview on the rowediting event which I am not sucessfull. Please find the code below:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { TextBox asdf = ((TextBox)GridView1.Rows[e.NewEditIndex].FindControl("TextBox1")); asdf.Text = Session["req_name"].ToString(); }I am getting Object reference not set to an instance of object.
I am using a templatefield. I've also tried without converting to a template field. The code is:
GridView1.Rows[e.NewEditIndex].Cells[15].Text = Session["req_name"].ToString();
Which is also not working. Please help.
Ashiq
robwscott
Star
8079 Points
1491 Posts
Re: How to Assign a Value to Gridview Cell on the Row Editing event
May 03, 2012 01:00 PM|LINK
are you sure that you have something in that session variable?
you should ALWAYS check this, meaning:
TextBox asdf = ...... if (Session["req_name"] != null) { asdf.Text = Session["req_name"].ToString(); // put a breakpoint here and see if the session variable is populated }Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
amit.jain
Star
11225 Points
1815 Posts
Re: How to Assign a Value to Gridview Cell on the Row Editing event
May 03, 2012 01:04 PM|LINK
Set new value in RowUpdating event
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) {TextBoxasdf = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1");amiT jaiN
ASP.NET C# VB Articles And Code Examples
karthicks
All-Star
31378 Points
5422 Posts
Re: How to Assign a Value to Gridview Cell on the Row Editing event
May 03, 2012 01:06 PM|LINK
hi, one thing you should understood that the edit template control will be rendered only after setting grid.EditIndex=e.NewEditIndex and Grid.DataBind(); i.e do like below
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex=e.NewEditIndex; GridView1.DataSource=ds; GridView1.DataBind(); // you should rebind the grid to set EditIndex TextBox asdf = ((TextBox)GridView1.Rows[e.NewEditIndex].FindControl("TextBox1")); asdf.Text = Session["req_name"] ==null? "": Session["req_name"].ToString(); }Karthick S
ziaulrahman
Member
483 Points
179 Posts
Re: How to Assign a Value to Gridview Cell on the Row Editing event
May 03, 2012 01:41 PM|LINK
Session["req_name"].ToString(); is not getting any value,So it cannot assign anything to the TextBox.
Mark answer if it helps.
ashiqf
Participant
868 Points
397 Posts
Re: How to Assign a Value to Gridview Cell on the Row Editing event
May 03, 2012 04:05 PM|LINK
Hi Karthik,
I am not binding to a dataset. I am using a sqldatasource:
SqlDataSource1.SelectCommand = "SELECT * FROM [ADCleanUpData] WHERE (LANID like '%" + TextBox1.Text + "%' or DisplayName like '%" + TextBox1.Text + "%') and ProjectID="+TextBox2.Text+""; SqlDataSource1.DataBind();Its not working still.
Ashiq
basheerkal
Star
10672 Points
2426 Posts
Re: How to Assign a Value to Gridview Cell on the Row Editing event
May 03, 2012 04:26 PM|LINK
It is impossible to get the controls in EditItemTemplate from RowEditing event. You can get it in prerender event.
protected void GridView1_PreRender(object sender, EventArgs e) { if (GridView1.EditIndex != -1) { TextBox TB = (TextBox)(GridView1.Rows[GridView1.EditIndex].FindControl("TextBox1")); TB.Text = "Some Text"; } }(Talk less..Work more)
ashiqf
Participant
868 Points
397 Posts
Re: How to Assign a Value to Gridview Cell on the Row Editing event
May 04, 2012 07:55 AM|LINK
It worked Great. Thanks for your help
Ashiq