EDIT2:
I tried something new I added this line of code:
$(self.ddlOwner + "option[value='" + this.owner_USER_ID +"']").attr("selected", "selected");
However this line of code does in fact set the value correctly but it does so on all the DDLs on the page. So if the value is 1 all four DDLs I have on the entire page set the value = 1.
End Edit2
I have a custom control DropDownList.
public class AssigneesDDL : System.Web.UI.WebControls.DropDownList
{
...
}
It gets populated onInit. And from the server side I would use a property to set its value.
this property:
public string ValueID
{
get { return base.SelectedItem.Value; }
set
{
ListItem li = base.Items.FindByValue(value.ToString());
if (li != null)
{
li.Selected = true;
}
else
{
ListItem li2 = new ListItem("", "");
base.Items.Add(li2);
li2.Selected = true;
}
}
}
Now I need to select the value from the client side and I am trying to do so with some JQuery, without any luck.
I have the Value captured but no idea how to set it. I've tried both:
$(self.ddlOwner).val(this.owner_USER_ID);
and
$(self.ddlOwner + "option:selected").val(this.owner_USER_ID);
Anybody have any ideas?
EDIT:
Oh and I've tried:
$(self.ddlOwner + "option:selected").text(this.owner_USER_ID);
this one actually adds a new line into the DDL with the right value, but it also adds that value to every DDL on my page. Which is odd. Not really sure why it does that.
Self.ddlOwner is ("#" + ddl.clientID). So I have the correct handle on the control.