I have a listview that has a nested listview which contain radboboxes in the itemtemplate. As such, the IDs (as far as I know) are useless to me.
For example, if I have 30 items, each one of those items is going to generate a new bobox so the names are going to be generated by asp. What I need is to be able to grab the selected value from whichever bobox is being worked by the user. I'm currently using jQuery and some absurd parent().parent().children()
type nonsense in order to find the correct bobox in relation to the submit button.
When submit button is clicked, I need it to find the selected value of the it's respective bobox so that I can send that to the post submission handler. The problem is that the .val()
jQuery method is not working. When I use that with something like:
$(this).parent().parent().children().children(".statusCbo").val();
I end up getting the text value, not the selected value. I triple checked to make sure that I had the fields bound correctly in the aspx file;
DataTextField = '<%#Eval("name") %>' DataValueField = '<%#Eval("id") %>'
But as I said, I'm ending up with the DataTextField value of the selected item. The best explanation I could get was that it had something to do with how the control is requesting the content (via ajax).
So at any rate, could anyone offer some suggestions on how to accurately get the selected value from the bobox?
UPDATE: I was able to gain reference to the object through a different means:
$(".submitTag").click(
function () {
var topLevel = $(this).closest(".CommentTopLevel");
var status = topLevel.find(".StatusTag").get_value();
//stub to test value
alert(status);
return false;
});
from here, if use status.val(), it will give me the text instead of the value (same issue as before). The documentation implies that I should use status.get_value(); but this is blowing up saying that the method is not supported from the object. Any ideas?
UPDATE: nevermind, I found that it is a jquery object being returned, so the method isn't included. Continuing to dig.
SOLUTION: There was just an extra step i needed to do to use traditional methods. I don't know what it took so long for it to click with me:
$(".submitTag").click(
function(){
var topLevel = $(this).closest(".CommentTopLevelTag"); //gets the parent container
var boBoxID = topLevel.find(".StatusTag").attr("ID"); //gets the clientID of the jQuery object
var boBoxRef = $find(boBoxID); //finds the control by id and brings back a non-jQuery object (useable)
var boBoxSelectedValue = boBoxRef.get_value(); //uses the Telerik method to get the selected value
});
I have a listview that has a nested listview which contain radboboxes in the itemtemplate. As such, the IDs (as far as I know) are useless to me.
For example, if I have 30 items, each one of those items is going to generate a new bobox so the names are going to be generated by asp. What I need is to be able to grab the selected value from whichever bobox is being worked by the user. I'm currently using jQuery and some absurd parent().parent().children()
type nonsense in order to find the correct bobox in relation to the submit button.
When submit button is clicked, I need it to find the selected value of the it's respective bobox so that I can send that to the post submission handler. The problem is that the .val()
jQuery method is not working. When I use that with something like:
$(this).parent().parent().children().children(".statusCbo").val();
I end up getting the text value, not the selected value. I triple checked to make sure that I had the fields bound correctly in the aspx file;
DataTextField = '<%#Eval("name") %>' DataValueField = '<%#Eval("id") %>'
But as I said, I'm ending up with the DataTextField value of the selected item. The best explanation I could get was that it had something to do with how the control is requesting the content (via ajax).
So at any rate, could anyone offer some suggestions on how to accurately get the selected value from the bobox?
UPDATE: I was able to gain reference to the object through a different means:
$(".submitTag").click(
function () {
var topLevel = $(this).closest(".CommentTopLevel");
var status = topLevel.find(".StatusTag").get_value();
//stub to test value
alert(status);
return false;
});
from here, if use status.val(), it will give me the text instead of the value (same issue as before). The documentation implies that I should use status.get_value(); but this is blowing up saying that the method is not supported from the object. Any ideas?
UPDATE: nevermind, I found that it is a jquery object being returned, so the method isn't included. Continuing to dig.
SOLUTION: There was just an extra step i needed to do to use traditional methods. I don't know what it took so long for it to click with me:
$(".submitTag").click(
function(){
var topLevel = $(this).closest(".CommentTopLevelTag"); //gets the parent container
var boBoxID = topLevel.find(".StatusTag").attr("ID"); //gets the clientID of the jQuery object
var boBoxRef = $find(boBoxID); //finds the control by id and brings back a non-jQuery object (useable)
var boBoxSelectedValue = boBoxRef.get_value(); //uses the Telerik method to get the selected value
});
Share
Improve this question
edited Mar 1, 2013 at 19:47
insertusernamehere
23.6k10 gold badges91 silver badges128 bronze badges
asked Mar 20, 2012 at 22:53
SinaestheticSinaesthetic
12.3k30 gold badges114 silver badges185 bronze badges
1
- can you post some html. Probably the html generated by asp by grabbing it from view source – DG3 Commented Mar 20, 2012 at 23:22
1 Answer
Reset to default 2Its been a little while since I've dealt with Telerik controls, but what you're doing is bypassing the apis Telerik has made for you to use, and that strikes me as a very bad thing. The next release of Telerik Controls could easily break your code.
Look, it shouldn't be that hard to pass the client id from the listview. There's several methods I'd tackle but I'll let you figure that on your own for now. Once you DO have the ClientID for the control, follow the example on telerik's site:
http://demos.telerik./aspnet-ajax/bobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx
Once you have that id do some
var bo = $find(someVarReferencingTheId);
Now you have a reference to the bobox in its clientside form. Now find some function that gets what you want from here:
http://www.telerik./help/aspnet-ajax/bobox-client-side-radbobox.html
...
PROFIT!
EDIT: that first link to demos.telerik. isn't really even needed, I just showed that because that's what I used to get that line of code (I could never remember if it's $get
or $find
I needed to use, unless I was doing a lot of Telerik clientside stuff at the time.).
EDIT 2: $get
and $find
are ASP.NET constructs, not Telerik's.