內的下拉列表中選擇的值,我打算給下拉列表中選擇值從C#代碼更改:改變嵌套轉發
<repeater >
<repeater>
<dropdown>
,我在aspx頁面的下拉 每一件事工作正常,添加一個數據源。但是我想改變下拉 的設定值的onload能夠顯示用戶以前選擇的名稱時,編輯表
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");//contain the id if the field
SarcShiftUser user = CRUD<SarcShiftUser>.Get(int.Parse(hf.Value)); //a method to select a user with a specific id and add it to object from class sarcshiftuser
if (user.id == 0)
ds.SelectedValue = "";
else
{
ds.SelectedValue = user.user_id + "";
}
}
}
}
}
shiftrepeater.DataBind();
}
我加入這個方法的Onload中繼器: 但沒有任何變化,以前的名字沒有顯示
P.S:用戶對象是正確的,user.user_id也是正確的 P.S 2:我試圖添加一個ds.DataBind();改變選擇,但給該錯誤後:
System.ArgumentOutOfRangeException: 'userdropdown' has a SelectedValue which is invalid because it does not exist in the list of items.
不知道從哪裏開始,你怎麼綁定/填充你的下拉菜單?您的下拉列表的值是[user.user_id +「」]? –