Value from ItemTemplate?

V

Vishal

Hello,

This should be simple question. I thought I could solve it
by my own, but unfortunaly I am not able. I have a
datagrid with several asp:TemplateColumn's. In that
template I have the <ItemTemplate> and the
<EditItemTemplate> template. Now I would like to retrieve
the value of the <ItemTemplate>. The template looks like
this:



<ItemTemplate>

<asp:Label text='<%# Container.DataItem("Banned") %>'
Runat="server" ID="lblBanned"></asp:Label>

</ItemTemplate>




However when I call my code then I get this error message:

Object reference not set to an instance of an object.
In this line -> If lblBanned.Text = "True" Then



Sub dgUsers_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs)

If (e.Item.ItemType = ListItemType.EditItem) Then

Dim lblBanned As Label = CType(e.Item.Cells
(11).FindControl("lblBanned"), Label)



If lblBanned.Text = "True" Then

....




Where is my fault?
 
S

Scott Mitchell [MVP]

Vishal said:
This should be simple question. I thought I could solve it
by my own, but unfortunaly I am not able. I have a
datagrid with several asp:TemplateColumn's. In that
template I have the <ItemTemplate> and the
<EditItemTemplate> template. Now I would like to retrieve
the value of the <ItemTemplate>. The template looks like
this:
[snip]

If (e.Item.ItemType = ListItemType.EditItem) Then

Right here's your problem. You are only working with the row being
edited. THat row's <EditItemTEmplate> is the one that has been
rendered, not it's <ItemTemplate>. So for the editable row, you *can't*
refer to its <ItemTemplate>, but only its <EditItemTemplate>.

Does this make sense?

Thanks

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top