Help Pls.Data grid itemtemplate

R

Raghu Raman

Hi,
am using the datagrid with the item template property.Inside it i have
the check box bounded to my database.I want the check box to be
automatically checked when it is loaded.
so i used the following code,

<Columns>
<asp:BoundColumn DataField="Tid" HeaderText="SI No"></asp:BoundColumn>
<asp:BoundColumn DataField="Tname" HeaderText="Name"></asp:BoundColumn>
<asp:TemplateColumn><ItemTemplate> <asp:CheckBox ID="chk" Runat=server
Checked ='<%#Container.DataItem("bools")%>'/>
</ItemTemplate> </asp:TemplateColumn>
</Columns>

-----------------------------id i run my app,
It tells the following error.

Compiler Error Message: CS0118:
'System.Web.UI.WebControls.DataGridItem.DataItem' denotes a 'property'
where a 'method' was expected

Source Error:



Line 23: using System.Web.UI.WebControls;
Line 24: using System.Web.UI.HtmlControls;
Line 25: using ASP;
Line 26:
Line 27:
----------------------------
Table structure:
~~~~~~~~~~~~~~~~~~~~~`
Tid Tname bools (nvarchar(5))
----------- -------------------- -----
1 one TRUE
2 two TRUE
6 six TRUE
Could u pls tell where i went wrong.

Thx & Regards
Raghu
 
E

Elton W

Try

<asp:CheckBox ID="chk" Runat=server Checked ='<%#
DataBinder.Eval(Container.DataItem, "bools")%>'/>

HTH

Elton Wang
(e-mail address removed)

-----Original Message-----

Hi,
am using the datagrid with the item template property.Inside it i have
the check box bounded to my database.I want the check box to be
automatically checked when it is loaded.
so i used the following code,

<Columns>
<asp:BoundColumn DataField="Tid" HeaderText="SI
No"> said:
<asp:BoundColumn DataField="Tname"
HeaderText="Name"> said:
<asp:TemplateColumn><ItemTemplate>
<asp:CheckBox ID="chk" Runat=server
 
R

Raghu Raman

Hi,Elton

Thx .But it tells the error,

'Specified cast not valid'.

Regards
Raghu
 

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
474,034
Messages
2,570,356
Members
47,002
Latest member
RobertoLip

Latest Threads

Top