hi,
This will come under "gridview_rowcommand" Event
please follow bellow steps:
step 1:
<asp:GridView ID="grd" runat="server" AutoGenerateColumns="false"
onrowcommand="grd_RowCommand">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lbl" Text='<%#Eval("ID") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="lnk" CommandArgument='<%#Eval("ID") %>' CommandName="vsr" Text="<img src='images/img1.jpg' border='0' />" runat="server">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Step 2:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "ID"; //this is index for update
myDataTable.Columns.Add(myDataColumn);
//
DataRow row;
for(int i=0;i<10;i++)
{
row = myDataTable.NewRow();
row["ID"] = i;
myDataTable.Rows.Add(row);
}
grd.DataSource = myDataTable.DefaultView;
grd.DataBind();
}
}
protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "vsr")
{
int i=Convert.ToInt32(e.CommandArgument);
GridView gr = (GridView)sender;
LinkButton lnk = (LinkButton)(gr.Rows[i].FindControl("lnk"));
lnk.Text = "<img src='images/img2.jpg' border='0' />";
}
}
Step 3:
add image folder in your project, add add 2 images in that folder
those image names img1.jpg and img2.jpg