Click here to Skip to main content

LinkButton Inside GridView Visibility

Sign Up to vote bad
good
See more: ASP.NET
i have linkbutton inside gridview
i want to change linkbutton visibility depende on value return from database
so i create that
 
<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 28 Aug '11
md_refay1.6K
Edited 28 Aug '11


Try something like this
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

Visible=<%# !(Convert.ToBoolean(Eval("IsNewRow"))) %>

Let me know if it work.
  Permalink  
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">
  Permalink  

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

add
  Print Answers RSS
Your Filters
Interested
Ignored
     
  1. OriginalGriff (1,245)
  2. Sandeep Mewara (1,037)
  3. VJ Reddy (545)
  4. SAKryukov (473)
  1. Sandeep Mewara (13,934)
  2. OriginalGriff (12,986)
  3. SAKryukov (8,004)
  4. VJ Reddy (5,145)
  5. losmac (5,065)


Advertise | Privacy | Mobile
Web03 | 2.5.120515.1 | Last Updated 29 Aug 2011
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid