Adding an Image Command Field to a GridView at Runtime

vishalneeraj-24503
Posted by vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 482
It's very easy to add an Image Command Field to a GridView dynamically as follows:

In Page Load write below code:-

In C#
if(!IsPostBack)
{
CommandField image_field = new CommandField();
image_field.ButtonType = ButtonType.Image;
image_field.SelectImageUrl = "~/images/select.png";
image_field.ShowSelectButton = true;
image_field.HeaderText = "Select";
grid_employee.Columns.Add(image_field);
grid_employee.DataBind();
}


In VB.NET

If(Not IsPostBack) Then
Dim image_field As New CommandField()
image_field.ButtonType = ButtonType.Image
image_field.SelectImageUrl = "~/images/select.png"
image_field.ShowSelectButton = True
image_field.HeaderText = "Select"
grid_employee.Columns.Add(image_field)
grid_employee.DataBind()
End If

Comments or Responses

Login to post response