Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > datagrid itemtemplate help

Reply
Thread Tools

datagrid itemtemplate help

 
 
angus
Guest
Posts: n/a
 
      06-16-2004
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


 
Reply With Quote
 
 
 
 
angus
Guest
Posts: n/a
 
      06-16-2004
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" <> wrote in message
news:...
> 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
>
>



 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      06-16-2004
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

"angus" <> wrote in message
news:...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically Change Text Property of Label in ItemTemplate in Datagrid Craig ASP .Net 1 10-09-2004 12:36 AM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM
Urgent help with ItemTemplate (datagrid) - databound DropDownList VB Programmer ASP .Net 6 09-01-2004 07:08 PM
Urgent help with ItemTemplate (datagrid) - databound DropDownList VB Programmer ASP .Net Datagrid Control 6 09-01-2004 07:08 PM
datagrid itemtemplate help angus ASP .Net Datagrid Control 1 06-20-2004 08:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57