Groups | Blog | Home
all groups > asp.net > may 2004 >

asp.net : Why I am Unable to read the content of a TemplateColumn ?


Natty Gur
5/26/2004 10:26:31 PM
Hi,


Template controls should hold inner control/s. you should access them
(inner controls) by using findcontrol to get reference to the template
inner control.

by the way why do you use OnItemDataBound event which fire when data
binds into grid item to get data grid items data ?


Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377


*** Sent via Developersdex http://www.developersdex.com ***
Ing. Rajesh Kumar
5/26/2004 11:05:37 PM
Hi everybody
I have a problem reading the content of a cell. When i use =
AutogenerateColumns =3D True or when i use
<asp:BoundColumn DataField=3D"COLUMN1" HeaderText=3D"COLUMN1"/> then i =
can simply read the content of a cell in the OnItemDataBound method =
using the following code :
For j =3D 0 To DT.Columns.Count - 1
If e.Item.Cells(j).Text =3D "something" Then Do Something
Next

Now i changed some columns to template columns as follows :
<asp:TemplateColumn HeaderText=3D"COLUMN1">
<ItemTemplate><%# DataBinder.Eval(Container.DataItem, "COLUMN1") =
%></ItemTemplate>
</asp:TemplateColumn>
and now i am unable to read the content of the Template Columns. It =
still reads BoundColumn's content. Last four hours i spend playing with =
it and still cannot read the value.

Just for testing i used the "nothing" comand as follows:
If e.Item.Cells(j).Text =3D "" Then Do Something
and it works. So it means that there is no value in the template column =
OnItemDataBound ?
Then how should i read the content of a TemplateColumn ?
Thanks in advance
Ing. Rajesh Kumar
5/27/2004 11:30:09 PM
Thanks Natty
I was missing the label control in the template column. I had some
True/False fields in my DataGrid and that's why i changed my DataGrid to use
Template columns so i could use checkboxes in it but for the display i used
this
<ItemTemplate><%# DataBinder.Eval(Container.DataItem, "AIT")
%></ItemTemplate>
<edititemtemplate><asp:CheckBox ID="chkEditAit" Checked=<%#
CheckBoxValueConverter(Container.DataItem("AIT")) %>
runat="server"/></edititemtemplate>
instead of this
<ItemTemplate><asp:Label ID="Label_4" Text=<%#
DataBinder.Eval(Container.DataItem, "AIT") %>
runat="server"/></ItemTemplate>
<edititemtemplate><asp:CheckBox ID="chkEditAit" Checked=<%#
CheckBoxValueConverter(Container.DataItem("AIT")) %>
runat="server"/></edititemtemplate>

The result was fine so i was fixed to find the problem elsewhere :)

Now, why I am using OnItemDataBound :
Well, OnItemDataBound I am checking the values of all the fields and
depending on those values i am changing the display property of the given
Cell. For example if a cell value is less than some given value then Cell's
background is red, etc.
Thanks a lot.
Raja


[quoted text, click to view]

AddThis Social Bookmark Button