Surya sasidhar
Surya sasidhar

Reputation: 30303

Visible false of button in gridview while data binding? In Asp.net?

In web application, I am going to disable the button while binding data, is it possible visibling false like this?

 <asp:Button ID ="btn" runat ="server"  CommandArgument='<%# Eval("id").ToString() == "1"? visble false: Visible true %>' />

Upvotes: 1

Views: 1528

Answers (3)

Ashwini Verma
Ashwini Verma

Reputation: 7525

Try this:

 <asp:Button ID="Button1" runat="server" Text="Button" Visible='<%#getVisibility()%>' OnClick="btn_Click" />

Code Behind:

public Boolean getVisibility()
{
   Boolean b = false;
   //get the boolean value based on your field condition
   b = Convert.ToBoolean(Eval("FieldValue").ToString() != "MatchCondition" ? "true" :     "false");
   return b;
}

Upvotes: 2

Naveed Butt
Naveed Butt

Reputation: 2901

Either do that in the data bound event or do it like this...

<asp:Button ID ="btn" runat ="server" Visible='<%# Eval("id").ToString() == "1"? "false" : "true" %>' />

Upvotes: 2

TheGeekYouNeed
TheGeekYouNeed

Reputation: 7539

Do it in the DataGrid RowDataBound event

Upvotes: 2

Related Questions