About use Container.DataItem() in ItemTemplate

A

alberthung01

Hi all,
I try to use Container.DataItem() in my DataGrid's ItemTemplate.
Somewhere it works fine.
eg.<input type=checkbox id='cb_select_<%# Container.DataItem("TAG_ID")
%>' value='<%# Container.DataItem("TAG_NAME") %>'>

but somewhere the server returns the expression was wrong.
<asp:ImageButton id="IB_Edit<%# Container.DataItem("TAG_ID") %>"
runat="server" ImageUrl="../Image/edit_image.gif"
CommandName="TO_EDIT"></asp:ImageButton>
or
<asp:ImageButton id="IB_Edit" runat="server" ImageUrl="../Image/
edit_image.gif" OnClientClick="alert('<%# Container.DataItem("TAG_ID")
%>');" CommandName="TO_EDIT"></asp:ImageButton>

Does anyone can tell me what situation i can use this method and what
i can't?

I would appreciate any help on this.
Thank you!
 
M

Masudur

Hi all,
I try to use Container.DataItem() in my DataGrid's ItemTemplate.
Somewhere it works fine.
eg.<input type=checkbox id='cb_select_<%# Container.DataItem("TAG_ID")
%>' value='<%# Container.DataItem("TAG_NAME") %>'>

but somewhere the server returns the expression was wrong.
<asp:ImageButton id="IB_Edit<%# Container.DataItem("TAG_ID") %>"
runat="server" ImageUrl="../Image/edit_image.gif"
CommandName="TO_EDIT"></asp:ImageButton>
or
<asp:ImageButton id="IB_Edit" runat="server" ImageUrl="../Image/
edit_image.gif" OnClientClick="alert('<%# Container.DataItem("TAG_ID")
%>');" CommandName="TO_EDIT"></asp:ImageButton>

Does anyone can tell me what situation i can use this method and what
i can't?

I would appreciate any help on this.
Thank you!

Hi...

OnClientClick="alert('<%# Container.DataItem("TAG_ID")> %>');"
in this markup you can see you are using double " double quote to
start and end ... but in side<%# Container.DataItem("TAG_ID")> %> you
are again using " double quote before and end of TAG_ID which is not a
well formated server tag...

your

<input type=checkbox id='cb_select_<%# Container.DataItem("TAG_ID")
%>' value='<%# Container.DataItem("TAG_NAME") %>'> worked because in this case you started with single quote rather than double quote...

if you want to modify attributes of your itemTemplate's element... you
can always do it in itemdatabound....

Thanks
Munna
www.kaz.com.bd
http://munnacs.110mb.com
 
G

Guest

<asp:ImageButton id="IB_Edit<%# Container.DataItem("TAG_ID") %>"
runat="server" ImageUrl="../Image/edit_image.gif"
CommandName="TO_EDIT"></asp:ImageButton>

could be written as

<asp:ImageButton id='<%# "IB_Edit" + Container.DataItem("TAG_ID") %>'
runat="server" ImageUrl="../Image/edit_image.gif"
CommandName="TO_EDIT"></asp:ImageButton>

And

<asp:ImageButton id="IB_Edit" runat="server" ImageUrl="../Image/
edit_image.gif" OnClientClick="alert('<%# Container.DataItem("TAG_ID")
%>');" CommandName="TO_EDIT"></asp:ImageButton>

could be as

<asp:ImageButton id="IB_Edit" runat="server" ImageUrl="../Image/
edit_image.gif" OnClientClick='(<%# "alert(\"" + Container.DataItem("TAG_ID")
%> + "\"");' CommandName="TO_EDIT"></asp:ImageButton>
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top