LinkButton with Eval ListView asp.net

1

I want to do this

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

inside the linkButton

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

That is, if data exists in "field1", it displays the data. Otherwise it displays "nothing". And, having data, clicking on linkButton passes to another page "promocao.aspx" the field2 and field3. The way it is, side by side, even though it does not have data in "field1" the LinkButton is available for click. Also, as it stands, in the URL field2 and field3 they get together.

    
asked by anonymous 15.06.2018 / 16:14

1 answer

1

Whether to use the Visible property of LinkButton to criticize whether it will be present or not, 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 no PostBackUrl create the desired options to redeem on the page of your configuration.

References LinkButton Web Server Control

    
15.06.2018 / 18:14