You must Sign In to post a response.
  • Category: ASP.NET

    How to visible the link button false for row in gridview

    My Gridview as follows

    Select Course Startdate Enddate

    Clickhere(Link Button) REO 10 May 2015 15 May 2015
    Clickhere(Link Button) 20 May 2015 25 May 2015
    Clickhere(Link Button) 28 May 2015 31 May 2015


    how to visibe false the link button for 2nd row and third row in Gridview.

    Because Whenever the Course value is empty in gridview. i do not want the link button.

    for that how can i do in asp.net using c#.

    What I have tried:

    My Gridview as follows

    Select Course Startdate Enddate

    Clickhere(Link Button) REO 10 May 2015 15 May 2015
    Clickhere(Link Button) 20 May 2015 25 May 2015
    Clickhere(Link Button) 28 May 2015 31 May 2015


    how to visibe false the link button for 2nd row and third row in Gridview.

    Because Whenever the Course value is empty in gridview. i do not want the link button.

    for that how can i do in asp.net using c#.
  • #764809
    Hi,

    If you want to set visibility false of linkbutton for course empty field then onrowdatabound event of gridview check the condition of course field.

    Refer below sample

    protected void gv_OnRowDataBound(object sender, GrdivewRowEventArgs e)
    {
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
    string course=((Label)e.Row.FindControl("lblCourse)).Text;
    if(course.ToString()=="")
    {
    ((LinkButton)e.Row.FindControl("lnk")).Visible=false;
    }
    }
    }


    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764813
    Hi,

    Check below link for sample code,

    http://stackoverflow.com/questions/17207271/enable-and-disable-link-button-on-gridview

    Let me know if this doesn't help.


    Regards,
    Asheej T K
    Microsoft MVP[ASP.NET/IIS]
    DotNetSpider MVM

  • #764814
    Hi,
    Try this:
    ((LinkButton)gvDemo.Rows[intRowIndex].FindControl("lnk")).Visible = false;
    OR
    ((LinkButton)gvDemo.Rows[intRowIndex].FindControl("lnk")).Enabled = false;
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764819
    Hai Rao,
    The easiest way to do this use the RowDataBound event handler and then get this button inside the event hanlder.
    Check the condition value and then you can use it.
    See the below code snippet which can be helpful to you:

    protected void gvCourse_OnRowDataBound(object sender, GrdivewRowEventArgs e)
    { if(e.Row.RowType==DataControlRowType.DataRow)
    {
    var courseLabel =((Label)e.Row.FindControl("lblCourseName));
    if(! IsNullOrEmpty(courseName.Text)
    {
    courseLabel.Visible=false;
    }
    }
    }

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764845
    simple you can loop on each row and check if the course value is empty then make link button visible false
    see below snippet
    for(int i=0;i<gvclassrooms.rows.count;i++)>
    {
    LinkButton lnkBtn = (LinkButton)gvClassRooms.Rows[i].FindControl("lnkRoom1");
    lnkBt.Visible = false;
    }

    OR you can do the same code on gridview bind event also (event name is RowdataBound)

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764937
    Hi
    Rao

    you can try this code



    Hi
    Rao

    If you need link button navigate some page means try this code


    DataTable dt = new DataTable();
    DataRow dr;
    dt.Columns.Add("Course");
    dt.Columns.Add("Grade");
    dt.Columns.Add("DOJ");
    dt.Columns.Add("DOP");
    dr = dt.NewRow();
    dr[0] = "ASM";
    dr[1] = "BB";
    dr[2] = DateTime.Now;
    dr[3] = DateTime.Now;
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr[0] = "";
    dr[1] = "CC";
    dr[2] = DateTime.Now;
    dr[3] = DateTime.Now;
    dt.Rows.Add(dr);


    dr = dt.NewRow();
    dr[0] = "BSM";
    dr[1] = "ZZ";
    dr[2] = DateTime.Now;
    dr[3] = DateTime.Now;
    dt.Rows.Add(dr);


    Grd1.DataSource=dt;
    Grd1.DataBind();


    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    TableCell statusCell = e.Row.Cells[1];
    Label lblCourse = e.Row.FindControl("lblCourse") as Label;
    LinkButton lnk = e.Row.FindControl("lnk1") as LinkButton;
    Label lblGrade = e.Row.FindControl("lbl2") as Label;
    if (lblCourse.Text !="")
    {
    lnk.Attributes["onclick"] = "javascript:window.open('WebForm3.aspx?Grade=" + lblGrade.Text + "')";
    }
    else
    {
    lnk.Visible = false;
    }
    }





    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments