datagrid itemtemplate help

Discussion in 'ASP .Net' started by angus, Jun 16, 2004.

  1. angus

    angus Guest

    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
    angus, Jun 16, 2004
    #1
    1. Advertising

  2. angus

    angus Guest

    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
    >
    >
    angus, Jun 16, 2004
    #2
    1. Advertising

  3. 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
    >
    >
    Eliyahu Goldin, Jun 16, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer
    Replies:
    6
    Views:
    557
    VB Programmer
    Sep 1, 2004
  2. Bennett Haselton
    Replies:
    1
    Views:
    5,314
    Joe Fallon
    Sep 24, 2004
  3. Craig
    Replies:
    1
    Views:
    3,521
  4. angus

    datagrid itemtemplate help

    angus, Jun 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    158
    Rick Spiewak
    Jun 20, 2004
  5. VB Programmer

    Urgent help with ItemTemplate (datagrid) - databound DropDownList

    VB Programmer, Sep 1, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    6
    Views:
    158
    VB Programmer
    Sep 1, 2004
Loading...

Share This Page