Click here to Skip to main content
15,886,789 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I write the code for dynamically create link button

C#
LinkButton lnk = new LinkButton();
           lnk.ID = "lnk";
           lnk.Text = "LinkButton";
           this.form1.Controls.Add(lnk);

     if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if (string.IsNullOrEmpty(e.Row.Cells[2].Text))
              {
                 if (e.Row.Cells[1].Text == "dontselect")
                  {
                    lnk.Visible = true;
                  }
              }
          }


Gridview as follows

Available Dates
        27 May 2015
        30 May 2015
        1  Jun 2015
          Emptyrow
        29 May 2015
        31 May 2015
        2  Jun 2015


i want to add link button when gridveiw row is empty.

I tried but it is not working

I want excepted output as follows


Available Dates
                                   27 May 2015
                                   30 May 2015
                                   1  Jun 2015
                                   Link button
                                   29 May 2015
                                   31 May 2015
                                   2  Jun 2015


In the empty row in gridview i want to display the link button in gridview.
Posted
Updated 23-Jul-15 22:38pm
v2
Comments
Er Daljeet Singh 27-Jul-15 7:52am    
Instead of writing this.form1.Controls.Add(lnk);
write
if (e.Row.Cells[1].Text == "dontselect")
{
lnk.Visible = true;
e.Row.Controls.Add(lnk);
}

hope this work

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