Now I want to perform click event on that Image Button.
How can I do that??
Tell me something about click events using Gridview.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 7, 2013, 8:05 PM EST
Define the event handler imageButtonCilck in Code-Behind:
protected void imageButtonCilck(object sender, EventArgs e)
{
//select the row
ImageButton imageButton = (ImageButton)sender;
TableCell tableCell = (TableCell)imageButton.Parent;
GridViewRow row = (GridViewRow)tableCell.Parent;
GridView1.SelectedIndex = row.RowIndex;
//pass parameters to iframe
iframe1.Page.Session.Add("id", row.Cells[idIndex].Text);
iframe1.Page.Session.Add("fIdx", row.Cells[fIdxIndex].Text);
}
Refer
http://forums.asp.net/t/1110689.aspx/1
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 7, 2013, 8:06 PM EST
All you need to do is set the CommandName of the ImageButton
for eg on Click of ImageButton I want to add a new record in the database then in that case I'll set the CommnadName Property of the ImageButton to let assume "Add". And In RowCommand Event of the Gridview I'll check the CommandName whether the RowCommand Event is fired because of ButtonClick or not. The following code logic gives you an overview.
protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)
{
//I'll check whether my imageButton was clicked or because of other
// postback event my RowCommandEvent of GridView1 is called.
if(e.CommandName.Equals("Add"))
{
if it is because of imageButton click then I'll perform my code logic over here.
=======
=======
=======
}
}
Hope that sovles your problem.
With Regards,
Vishal Gilbile.