Get selected index from gridview with jquery
All i want is to get the selected index (or selectedvalue or se开发者_运维百科lectedDataKey) of a gridview with jquery so i can use jquery ajax to load its data with that ID as parameter.
How can i get it with jquery?
Thank you.
Why would you want that?
Here is an idea.
Set SelectedRowStyle="myselection"
.
Now place a label in GridView in any existing TemplateField.
(Dont create any new asp:TemplateField
because it will add a new column)
<asp:Label ID="HiddenLabel" runat="server"
CssClass="myindex"
Text='<%# Container.DisplayIndex %>'
style="display:none;"/>
Now retrieve the selected row index like this.
var selectedIndex = -1;
if($(".myselection").length){
selectedIndex = $(".myselection .myindex").html() - 0;
}
Update:
Multiple GridViews? You could still do that. Give each GridView a separate CssClass. CssClass="grid1"
var selectedIndex = -1;
if($(".grid1 .myselection").length){
selectedIndex = $(".grid1 .myselection .myindex").html() - 0;
}
I do not know of any simpler way. Sorry.
精彩评论