Using RowCreated event in Gridview to update a template

L

louie

I have created a Gridview both using an ObjectDataSource and an SQLDataSource.
I amend attributes in a TemplateField, this works fine until I sort the
data, by clicking on the column heading, then i get the error in the
RowCreated Event
Run-time exception thrown : System.NullReferenceException - The pointer for
this method was null.
This is because the object e.Row.DataItem is set to Nothing.

I can replace this code with <%# CreateHTML(Eval("FieldName")) % > and
create inline HTML, this works fine. What am I missing?
Any help much appreciated.


Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lName As String = DataBinder.Eval(e.Row.DataItem,
"FieldName").ToString
Dim lBut As Web.UI.WebControls.Button
lBut = e.Row.FindControl("tstBut")
lBut.Text = lName
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top