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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vishal GilbilePosted Mar 8, 2013, 1:06 AM
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.
Satyapriya NayakPosted Mar 8, 2013, 1:05 AM
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