datagrid itemtemplate help

  • Thread starter Thread starter angus
  • Start date Start date
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
 
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
 
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
 
Back
Top