After searching around, still puzzled. Why is it that I get blanks for all references to my cells in a databound gridview? All below render blank.
e.Row.Cells(1).Text
e.Row.Cells(2).Text
e.Row.Cells(3).Text
depends on the event ..are you binding with a DataSource control OR in the codebehind? let me guess in the meanwhile ..most probably you're in the RowUpdating event... need to cast them as TextBoxes
TextBox tbox = e.Row.Cells(1).Controls(0) as TextBox;
and then get the text value as tbox.Text
if that doesn't answer please post some code and details
EDIT, just discovered a typo.!!! It was:
Protected Sub GridView1_Rowdatabound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.Rowcreated
not sure how that got there!
I am doing this in the Rowdatabound event. The gridview binds from datasource and renders nicely. Now I am trying to operate on the rows and attempting this:
Dim zo As String = e.Row.Cells(2).Text and nothing but blanks. The first cell happens to be a linkbutton.
Fonzie
Participant
1891 Points
1168 Posts
e.Row.Cells(i).Text always blank
Oct 02, 2009 06:11 PM|LINK
e.Row.Cells(1).Text
e.Row.Cells(2).Text
e.Row.Cells(3).Text
PeteNet
All-Star
81342 Points
11398 Posts
Re: e.Row.Cells(i).Text always blank
Oct 02, 2009 06:17 PM|LINK
depends on the event ..are you binding with a DataSource control OR in the codebehind? let me guess in the meanwhile ..most probably you're in the RowUpdating event... need to cast them as TextBoxes
TextBox tbox = e.Row.Cells(1).Controls(0) as TextBox;
and then get the text value as tbox.Text
if that doesn't answer please post some code and details
have you got the correct reference to the Row?
Peter
Fonzie
Participant
1891 Points
1168 Posts
Re: e.Row.Cells(i).Text always blank
Oct 02, 2009 06:21 PM|LINK
Protected Sub GridView1_Rowdatabound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.Rowcreated
not sure how that got there!
I am doing this in the Rowdatabound event. The gridview binds from datasource and renders nicely. Now I am trying to operate on the rows and attempting this:
Dim zo As String = e.Row.Cells(2).Text and nothing but blanks. The first cell happens to be a linkbutton.
PeteNet
All-Star
81342 Points
11398 Posts
Re: e.Row.Cells(i).Text always blank
Oct 02, 2009 06:45 PM|LINK
first make sure you check for DataRow, refer here:
for template controls you'll have to find them and cast them to be able to get or set their properties/values
Dim lbutton As LinkButton = TryCast(e.Row.FindControl("LinkButton1"), LinkButton)
will cast it to a Linkbutton with ID = "LinkButton1" on your gridview
and then you could access its properties lbutton.PostBackUrl etc
also, always better to ensure that the control has been found before you access its properties so
Dim lbutton As LinkButton = TryCast(e.Row.FindControl("LinkButton1"), LinkButton)
If lbutton IsNot Nothing Then
'lbutton.PostBackUrl =
End If
but for boundfields you can get the Cells(n).Text
so is the problem with the BoundFields OR the TemplateFields?
Peter
naveenj
Contributor
6164 Points
1130 Posts
Re: e.Row.Cells(i).Text always blank
Oct 03, 2009 10:02 AM|LINK
Hi Fonzie,
The answer lies in how u r binding ur GridView.
Are you using
1.AutoGenerateColumns="true"
2. asp:TemplateField
3. asp:BoundField
Just paste a snippet of your gridviews markup so that we can help u better
Naveen Jose
ASP.NET Freelancer, Consultant
Please remember to click Mark as Answer on the post that helps you
Fonzie
Participant
1891 Points
1168 Posts
Re: e.Row.Cells(i).Text always blank
Oct 05, 2009 03:07 PM|LINK