I tried changing the selected dropdownlist value from C # code:
<repeater >
<repeater>
<dropdown>
and I add the data source on the aspx page in the drop-down list everything works fine .. but I want to change the selected onload value of the drop-down list to show the user the previous selected name when editing the table
protected void PrepairDropDownList(object sender,EventArgs e)
{
shiftrepeater.DataBind();
if (shiftrepeater.Items.Count > 0)
{
for (int shiftcount = 0; shiftcount < shiftrepeater.Items.Count; shiftcount++)
{
Repeater temp = (Repeater)shiftrepeater.Items[shiftcount].FindControl("saturdayrepeater");
if (temp.Items.Count > 0)
{
for (int count = 0; count < temp.Items.Count; count++)
{
DropDownList ds = (DropDownList)temp.Items[count].FindControl("userdropdown");
HiddenField hf = (HiddenField)temp.Items[count].FindControl("hiddenid");
SarcShiftUser user = CRUD<SarcShiftUser>.Get(int.Parse(hf.Value));
if (user.id == 0)
ds.SelectedValue = "";
else
{
ds.SelectedValue = user.user_id + "";
}
}
}
}
}
shiftrepeater.DataBind();
}
I add this method to the Onload repeater: but nothing has changed, and the previous name did not show
PS: the user object is correct and user.user_id is also true PS 2: I tried adding ds.DataBind (); after changing the selected, but here is the error:
System.ArgumentOutOfRangeException: 'userdropdown' has a SelectedValue which is invalid because it does not exist in the list of items.
source
share