Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there
I have a gridview and a column is added as image button template field..I want to delete the selected row with image button with confirmation message box.
The problem is how to get the selected row using that image button....?
I have added Commandname="Select" in the design.
But it doesnt work....
how to do this?

Thank you in advance
Posted
Comments
Sandeep Mewara 28-Aug-10 5:45am    
Bottom line... you can use Image button to follow the delete command.. try!
Ankur\m/ 28-Aug-10 6:25am    
I have deleted your answer which was actually a question. You have already put up a new question for the same. Do as I suggested in my comment and if you are still unable to solve it, add your code snippet in the new question.

I believe the gridview lets you show a delete command button, which can then be configured to show whatever graphic you like, and return the primary key. You should never delete or add data to your gridview. Update your data source and rebind.
 
Share this answer
 
Comments
aswathy.s.88 28-Aug-10 2:11am    
ya delete command is there and it is possible to delete with that...
But I'm assigned to do it with an image button
Christian Graus 28-Aug-10 2:33am    
Assigned by who, morons ? You're the developer, tell them the right way to do it. You can use an image to skin a delete button.
I haven't tried this, but I guess this should work.

Handle RowCommand event of the GriedView. Check if the CommandName is "select" (that's what you have named it).
If yes, you can get the selected row index using CommandArgument. Then perform the delete task.
Code will be something like this.
C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {
        int index = Convert.ToInt32(e.CommandArgument);

        //Now you have the selected row index. So write code to delete the row.
    }
}


Let me know if it works or not.
 
Share this answer
 
Comments
aswathy.s.88 28-Aug-10 5:49am    
Ya I had tried out the same code before...
but the problem is the Gridview1_RowCommand is raised twice...How to avoid this?
Ankur\m/ 28-Aug-10 6:20am    
The event is raised twice? That should not happen. You must be doing something wrong. Debug the whole code and check after which point, the event is raised again. I think it would be your delete function. Check it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900