Monday, March 14, 2011

Conditionally hide CommandField or ButtonField in Gridview.

Suppose FieldName is the Bit field which tells whether the link should be visible true or false 

so design your gridview template like this


</asp:TemplateField>
<asp:TemplateField HeaderText="Auth">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Text="as" Visible='<%# SetVisible(Eval("FieldName"))%>'
CommandName="Auth" runat="server">MoreInfo</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>


now write your server code like this

public bool SetVisible(object obj_Status)
{
if(obj_Status==DBNull.Value)
return false;
else if (Convert.ToBoolean(obj_Status))
return true;
else
return false;
}
 
 

2 comments:

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...