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

    Link button should be visible false

    I have grigview as follows

    Course Code Days Startdate Enddate

    Clickhere(Link Button) ASM 5 05 May 2016 10 May 2016
    Clickhere(Link Button) 12 May 2016 17 May 2016
    Clickhere(Link Button) 21 May 2016 25 May 2016

    I dont want 2nd row and third row link button in gridview because in gridview
    Code(2nd column) second and thrid row code is empty.
    Whenever empty in Code i do not want link button. i want to set visble false.
    for that my code as follows in Gridview row databound
    protected void gvRank_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    LinkButton lnk= (LinkButton)e.Row.FindControl("LinkButton2");
    TextBox text = (TextBox)e.Row.FindControl("Code");
    if (text == null && lnk == null)
    {
    lnk.Visble = false;
    }
    else
    {
    lnk.Visible = True;
    }
    }
    }
    But in gridview output i get as follows

    Course Code Days Startdate Enddate
    ASM 5 05 May 2016 10 May 2016
    12 May 2016 17 May 2016
    21 May 2016 25 May 2016
    In course column all the link button are visible false. i want only the second row and third row link button only visible false.
  • #764863
    I think the condition you are giving is seems to be wrong,
    you have checked like
    if (text == null && lnk == null)
    {
    lnk.Visble = false;
    }
    else
    {
    lnk.Visible = True;
    }
    if txt and lnk is null then link button is invisible, and I think in your case all txt and lnk is null, you need to check for cell instead

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

  • #764864
    Please follow the below code to hide the linkbutton only if the rowIndex = 1 and 2.

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowIndex == 1 || e.Row.RowIndex == 2)
    {
    LinkButton lnk= (LinkButton)e.Row.FindControl("LinkButton2");
    TextBox text = (TextBox)e.Row.FindControl("Code");
    if (text == null && lnk == null)
    {
    lnk.Visble = false;
    }
    else
    {
    lnk.Visible = True;
    }
    }
    }

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #764875
    Hi,

    You already raise the same query in different link, I request you to please check that or else refer my comments in that link by below.

    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/

  • #764876
    Hi,
    You are checking founded controls == null, at no point you will get them as null because they always exist in each row.
    Instead, just check TextBox.Text value == ""
    i.e.
    if (text.Text == "")
    {
    lnk.Visble = false;
    }
    Hoping that you have assigned text to 'Code' textbox as Text='<%# Eval("dbColumnName") %>' in aspx.
    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764889
    Hai Rao,
    I think we already provided the solution for this issue. So you can go back to the old forum and check. If you are not satisfied with the answer, please reply to the same post.
    This will prevent duplicate to the forum questions.
    Hope it will be helpful to you.

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

  • #764936
    Hi
    Rao

    you can follow 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.

  • #764975
    You are finding the control and checking whether is it null or not. All the rows controls will be there but you have to check the values is there or not

    Try the following code

    protected void gvRank_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    LinkButton lnk= (LinkButton)e.Row.FindControl("LinkButton2");
    TextBox text = (TextBox)e.Row.FindControl("Code");
    if (text.Text == "" && lnk.Text == "")
    {
    lnk.Visble = false;
    }
    else
    {
    lnk.Visible = True;
    }
    }
    }

    By Nathan
    Direction is important than speed


Sign In to post your comments