Click here to Skip to main content
15,071,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have linkbutton inside gridview
i want to change linkbutton visibility depende on value return from database
so i create that

C#
<asp:LinkButton ID="Lnk" runat="server"  CommandArgument='<%# Bind("ArrivalMasterID") %>' Text="Cost" <big>Visible='<%# Bind("IsNewRow") %>'</big> /> 

but i have one problem
i wnat linkbutton visibility to be reverse to isnewrow value
mean if isbewrowvalue=ture then linkbutton.visible=false
i need to do it from html code not from c# codey
any help
Posted
Updated 28-Aug-11 20:04pm
v3

Try something like this
C#
if (e.Row.RowType == DataControlRowType.DataRow)
                  {
YourClass object = (YourClass)e.Row.DataItem;
 LinkButton lnkbtn= (LinkButton)e.Row.FindControl("Lnk");
  lnkbtn.Visible = !Convert.ToBoolean(object.Value);   
}           


Well, This will do the job for you as per your current implementation. use a Not ( ! ) Operator
<br />
Visible=<%# !(Convert.ToBoolean(Eval("IsNewRow"))) %>

Let me know if it work.
   
v4
on gridview rowdatabound event you can add following code keep your <%# Bind(!"IsNewRow") %> which is as datakey field of gridview.

bool Isnewrow
if (e.Row.RowType == DataControlRowType.DataRow)
{

Isnewrow= Convert.ToBool(gridview.DataKeys[e.Row.RowIndex].Values[0]);

LinkButton lnkButton = (LinkButton)e.Row.FindControl("lnkViewDetails");
if(Isnewrow)
{
lnkbutton.visible=true;
}
else
lnkbutton.visible=false;


To add Isnewrow field as datakey of gridview


<asp:GridView ID="gridview1" AllowPaging="true"
AutoGenerateColumns="false" DataKeyNames="Isnewrow "
runat="server" ShowFooter="true"
onrowdatabound="grdCustomerFeedback_OnRowDataBound">
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900