Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  165] [ 2]  / answers: 1 / hits: 30798  / 9 Years ago, mon, june 1, 2015, 12:00:00

Let me elaborate ... below is my partial gridview with a button field ... what I want is the text value of the button to use in building a url:



<asp:GridView CssClass=gridUser ID=UsersGrid ClientIDMode=Static runat=server AllowPaging=true AllowSorting=true PageSize=5 OnPageIndexChanging=PageIndexChange OnRowCommand=Paging OnSorting=SortPage OnRowCreated=RowCreated
AutoGenerateColumns=false>

<PagerSettings Mode=NextPreviousFirstLast FirstPageImageUrl=~/Images/Navigation/firstpageIcon.png LastPageImageUrl=~/Images/Navigation/lastpageIcon.png
NextPageImageUrl=~/Images/Navigation/forwardOneIcon.png PreviousPageImageUrl=~/Images/Navigation/backOneIcon.png Position=Bottom />

<Columns>
<asp:TemplateField HeaderText=User Name HeaderStyle-CssClass=gridHeader>
<ItemTemplate>
<asp:Button ID=UserLink ClientIDMode=Static runat=server Text='<%#Eval(UserName) %>' CssClass=linkButton OnClientClick = return GetSelectedRow(this)></asp:Button>
</ItemTemplate>
</asp:TemplateField>


and here is my javascript :



 $(.linkButton).click(function () {
var ul = document.getElementById('UserLink');
var row = ul.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
var Userid = row.cells[0].childNodes[1].value;
var User = Userid;
alert(Row is : + row + RowIndex is : + rowIndex + User ID is + User);
});


My issue is that my row returned is the first row ... not the selected row ... how do I get the selected row? Thank you for any assistance.


More From » jquery

 Answers
42

Try this... Change naming conventions according to your requirement



<script type = text/javascript>
function GetSelectedRow(UserLink) {
var row = UserLink.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
var Userid = row.cells[0].innerHTML;
alert(RowIndex: + rowIndex + Userid : + Userid + );
return false;
}
</script>

[#66379] Friday, May 29, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hadens

Total Points: 142
Total Questions: 98
Total Answers: 100

Location: Kenya
Member since Mon, Jun 14, 2021
3 Years ago
hadens questions
;