e.CommandArgument is empty in OnRowCommand event of the Gridview

Posted by Webmaster under ASP.NET on 9/6/2008 | Views : 17843 | Status : [Administrator] | Replies : 2
I have a button in one of the column of my GridView called Remove and I am placing a LinkButton inside TemplateColumn for this.

When I am trying to get the clicked row for that GridView in OnRowCommand event as
GridViewRow row = GridViewSelected.Rows[int.Parse(e.CommandArgument.ToString())];

I am getting error as e.CommandArgument value is coming as empty ("").

Any help?

________________________
Posted on behalf of Poster

Best regards,
Webmaster
http://www.dotnetfunda.com



Responses

Posted by: Edwinjoseph on: 2/18/2011 [Member] Starter | Points: 25

Up
0
Down
hi,
i used the Container.DataItemIndex. but my grid is displaying 5 rows per page so when i go to the next page and click the first row i need to get the index as 1 , but it shows a error index out of range.. but it works well for the first page. can u pls help me fix this issue

thanks in advance

edwin

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Webmaster on: 9/6/2008 [Administrator] HonoraryPlatinum

Up
0
Down
Try to specify CommandArgument value as Container.DataItemIndex for the LinkButton as follows
<asp:LinkButton ID="lnkRemove" runat="server" Text="Remove" CommandName="remove" CommandArgument='<%# Container.DataItemIndex %>' />
Hopefully that should work.

Please let me know if it works.

Best regards,
Webmaster
http://www.dotnetfunda.com

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response