Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Please provides solutions to a frustrating issue: GridViewCommandEventArgs doesn't expose the Row that raised the event. Say you need an itemTemplate for a link button to execute deletes.; how do you get a reference to the correct row? While the datagrid's DataGridCommandEventArgs exposed the row through it's Item property & e.Item.ItemIndex GridViewCommandEventArgs only three properties: CommandName, CommandArgument & CommandSource (which provides a reference to the gridview itelf).

I searched a lot but not able to get any solution.Please help or suggest any work around.
Posted
Updated 24-May-12 23:50pm
v2
Comments
The Doer 25-May-12 6:07am    
what type of event your GridView is raising??
Sugato Pal 25-May-12 6:17am    
Like item in datagrid i want to access selected row values for action of GridViewCommandEventArgs.But the available attributes are CommandArgument,CommandName,CommandSource.No Row attribute is available.Please help.
hitech_s 25-May-12 7:04am    
why dont you place link button and raise rowcommand event of gridview then you will get commandname,command argument
Sugato Pal 25-May-12 7:11am    
Yes Hitech_s,you are correct.Consider there is 4*4 gridview.Now i am selecting 3rd row 1st column (which is a link button).So Onrowcommand i can get the value of 3rd row 1st column by CommandSource.But i want also the values of 3rd row 2nd column,3rd column,4th column.I think i am able to clear your doubt..Please guide me if you have any opinion.

1 solution

Same Pinch...! Me too sucked with the same Problem, and finally end up with this:-) Here i have Used ImageButton instead of Link Button..!


Put DataKey Property to your Grid as-

VB
<asp:GridView ID="gvUser" Width="100%" runat="server" CssClass="Gridview"
AutoGenerateColumns="false" showfooter="true"  DataKeyNames="UserID"
BorderColor="white" HeaderStyle-BackColor="#e0ffff"
HeaderStyle-BorderColor="#b0c4de" FooterStyle-BackColor="white"
onrowcancelingedit="gvUser_RowCancelingEdit" onrowdeleting="gvUser_RowDeleting"
onrowediting="gvUser_RowEditing" onrowupdating="gvUser_RowUpdating" >


Here i have created an event for row deleting-

C#
protected void gvUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    string id = gvUser.DataKeys[e.RowIndex].Value.ToString();

    _objUserBAL.fnDeleteDetailByID("tt_Users", "UserId", id);
    BindUserDataConfig();
    BindReportingPerson();
}



USe DatakeyName to get the raised event.

All the Best:-)
 
Share this answer
 
v2

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