Add boundfield column in gridview at runtime

First of all you have to set the gridview with two bounded column like (name,age)
now if u want to add new column bounded column dob at the run time then follow this code..


protected void Button1_Click(object sender, EventArgs e)
{
BoundField boundField = new BoundField();
boundField.DataField = "DOB";
boundField.HeaderText = "DOB";
boundField.HtmlEncode = false;
boundField.DataFormatString = "{0:d}";
GridView1.Columns.Add(boundField);
//bind gridview..

bindgridview();
}


note: data source must contain the dob column...(i.e. dataset,datatable, datareader and so on)


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: