datagrid itemtemplate help

A

angus

Dear All,

In my datagrid, i want to add a logic to it. that is, if the result for the
data equals to "Yes",
a "asp:label" control will be displayed; otherwise a "asp:imagebutton"
control will be shown

<ItemTemplate>
<% if DataBinder.Eval(Container.DataItem, "boflag").equals("Yes") then%>
<asp:Label id="Label1" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"boflag")%>'></asp:Label>
<% Else %>
<asp:imagebutton id="imgBtnUpdate" runat="server" NAME="Imagebutton3"
ImageUrl="no.gif"></asp:imagebutton>
<% end if %>
</ItemTemplate>

However, "<% if DataBinder.Eval(Container.DataItem,
"boflag").equals("Yes") then%> " this is not valid.

So, how can i get the data to compare the value.

Thank you.

Regards,
Angus
 
A

angus

Hello Angus,



You can do something like that. Hope that it can help

Dim lblTemp As Label

For i As Integer = 0 To mydatagrid.Items.Count - 1

lblTemp = mydatagrid.Items(i).Cells(n).FindControl("Label1")

If Not lblTemp.Text.Equals("Yes") Then

mydatagrid.Items(i).Cells(n).Controls.add(<img button control here>)

End If

Next
 
E

Eliyahu Goldin

Angus,

ASP.NET page is not a program. It can't run statements. You can databind
Visible property of your Label and ImageButton to the expression you have in
the if-part.

Eliyahu
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top