Linkbutton with Eval Listview Asp.net

Asked

Viewed 62 times

1

I want to do this

<%# Eval("campo1").ToString() == "nada consta" ? "nada consta" : Eval("campo1")%>         

within the linkButton

<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl= '<%# 
"~/Promocao.aspx?ID="+Eval("campo2") + 
Eval("campo3")%>'>...+infos</asp:LinkButton>

That is, if there is data in "field1", it displays the data. Otherwise it displays "nothing is". And, having data, when clicking on linkButton passes to another page "promocao.aspx" the field2 and field3. The way it is, next to each other, even without data in "field1" Linkbutton is available for click. Besides, the way it is, in the URL the field2 and field3 are together.

  • 1

    Strange explanation: "That is, if there is a field1," Let’s go if you want Linkbutton to appear only if the field1 exists? as well, has to explain better?

  • @I’m sorry, the explanation was lacking in detail. If it is not "nothing is in" field1 it will show the data, otherwise linkButton does not need to appear. If Simm, the user will then click on "...+Infos" going to another page, where I will retrieve the data from field2 and field3 - to mount a payment request - that will always exist, once there is field1. I also want the URL to separate the parameters campo2 and campo3 and not together sequentially, A space between them would be good.

  • A space between them would be good -> is not correct so, what you do and create an ID1 and pass the field3 what you think?

  • Yes @Virgilionovic

1 answer

1


You can use the property Visible of Linkbutton to criticize whether or not it will be present, example:

<asp:ListView ID="ListView1" runat="server">
    <ItemTemplate>                    
        <div>                        
            <asp:LinkButton ID="LinkButton1" 
                PostBackUrl='<%#string.Format("~/Promocao.aspx?id={0}&id1={1}", Eval("campo2"),Eval("campo3"))%>' 
                runat="server" 
                Visible='<%#Eval("campo1").ToString()!="nada consta"%>'>
                    Item
            </asp:LinkButton>    
            <asp:Literal 
                ID="Literal1"
                runat="server"
                Text='<%#Eval("campo1").ToString()=="nada consta"?"nada consta":""%>'>
            </asp:Literal>                    
        </div>
    </ItemTemplate>
</asp:ListView>

and in the PostBackUrl create the desired options to redeem on your configuration page.

References Linkbutton Web Server Control

  • When it appears, instead of the field1 data it displays "item". ' Not right.

  • 1

    @Daniel did not understand?

  • 1

    Friend is an example even in your @Daniel has something written

  • True. I’m exploring this example here. I want the data and control to appear so the user can click. If there is no data to display, then display "nothing is in", in which case, linkButton does not appear, only the text "nothing is in".

  • @Daniel is hard to understand!

  • According to the excellent example above, when nothing is in" field1" the control disappears. This is correct. However, I want a text to appear so that the user knows that nothing appears in the field of this record. And when it appears, the control appears. This is correct. However, I want not only control to appear, but the data of "field1".

  • 1

    @Daniel just put a literal and invert the Visible information, I made the edit.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.