I am building an application for tickets using a gridview. Each row has an option to edit the ticket or delete it. I did it by adding 2 selected button on each row.
Now, the issue is that I cannot tell which button is clicked since they both get me to the same event which is onselectedindexchanged.
They dont have any ID so I cannot run in a loop and find the ID and they dont return the text with cell.text since I got null on both buttons.
How can I retrive information on which selected button was clicked in a specific row ? It will be enough to know the column name but how do I do that ?
Your answer would be gread if I was using ButtonField, but I am using Commandfield and CommandName is not valid attribute for this type. Any other suggestion ?
talbe
Member
2 Points
36 Posts
How to know which column in gridview when using Commandfield
Jan 23, 2013 11:33 AM|LINK
Hi,
I am building an application for tickets using a gridview. Each row has an option to edit the ticket or delete it. I did it by adding 2 selected button on each row.
Now, the issue is that I cannot tell which button is clicked since they both get me to the same event which is onselectedindexchanged.
They dont have any ID so I cannot run in a loop and find the ID and they dont return the text with cell.text since I got null on both buttons.
How can I retrive information on which selected button was clicked in a specific row ? It will be enough to know the column name but how do I do that ?
goel.ankit
Contributor
2531 Points
513 Posts
Re: How to know which column in gridview when using Commandfield
Jan 23, 2013 11:36 AM|LINK
you can pass the commandargument..let me get you an example.
Ankit
(Please select 'Mark as Answer' if my response has helped you.)
goel.ankit
Contributor
2531 Points
513 Posts
Re: How to know which column in gridview when using Commandfield
Jan 23, 2013 11:40 AM|LINK
for your use CommandName should be sufficient
<asp:ButtonField ButtonType="Link" CommandName="Approval" Text="Approve" /> <asp:ButtonField ButtonType="Link" CommandName="Reject" Text="Reject" /> CS File -> if (e.CommandName == "Approval") { } if (e.CommandName == "Reject") { }Ankit
(Please select 'Mark as Answer' if my response has helped you.)
goel.ankit
Contributor
2531 Points
513 Posts
Re: How to know which column in gridview when using Commandfield
Jan 23, 2013 11:40 AM|LINK
for your use CommandName should be sufficient
<asp:ButtonField ButtonType="Link" CommandName="Approval" Text="Approve" /> <asp:ButtonField ButtonType="Link" CommandName="Reject" Text="Reject" /> CS File -> if (e.CommandName == "Approval") { } if (e.CommandName == "Reject") { }Ankit
(Please select 'Mark as Answer' if my response has helped you.)
stanly
Star
13201 Points
2490 Posts
Re: How to know which column in gridview when using Commandfield
Jan 23, 2013 11:44 AM|LINK
Check this url, ypu will find your answer here
http://weblogs.asp.net/gurusarkar/archive/2010/09/22/get-gridview-rowindex-upon-button-click.aspx
weblogs.asp.net/stanly
talbe
Member
2 Points
36 Posts
Re: How to know which column in gridview when using Commandfield
Jan 23, 2013 11:51 AM|LINK
Your answer would be gread if I was using ButtonField, but I am using Commandfield and CommandName is not valid attribute for this type. Any other suggestion ?
oned_gk
All-Star
36078 Points
7363 Posts
Re: How to know which column in gridview when using Commandfield
Jan 23, 2013 11:55 AM|LINK
Suwandi - Non Graduate Programmer
talbe
Member
2 Points
36 Posts
Re: How to know which column in gridview when using Commandfield
Jan 23, 2013 12:03 PM|LINK
So I need to change my code to template instead of commandfield....I guess this is what I will do if I have no other choice.
talbe
Member
2 Points
36 Posts
Re: How to know which column in gridview when using Commandfield
Jan 23, 2013 12:34 PM|LINK
Ok, it is working fine.... Can you explain to me what this do:
CommandArgument='<%# Container.DataItemIndex %>' ?
Thanks,
oned_gk
All-Star
36078 Points
7363 Posts
Re: How to know which column in gridview when using Commandfield
Jan 23, 2013 12:48 PM|LINK
When using rowcommand you can pass value using CommandArgument. For example CommandArgument="abc".
Your sample will set commandargument property value using rowindex value.
You can also make row namber using label, set text property : text = '<%# Container.DataItemIndex + 1 %>'
Suwandi - Non Graduate Programmer