换档表asp.net中继器内的下拉菜单

换档表asp.net中继器内的下拉菜单,asp.net,drop-down-menu,Asp.net,Drop Down Menu,我正在尝试在asp.net中构建一个移位表 我使用一个主中继器进行轮班,内部中继器用于轮班人员 <repeater .... shift 1 - 2 - 3 .... > <repeater .... person 1 - 2 - 3 inside each shift > <dropdown .... to select the person name > 班次1 中继器下拉列表1 中继器下拉菜单2 . . 班次2 中继器下拉列表

我正在尝试在asp.net中构建一个移位表

我使用一个主中继器进行轮班,内部中继器用于轮班人员

<repeater .... shift 1 - 2 - 3 .... >
   <repeater .... person 1 - 2 - 3 inside each shift >
      <dropdown .... to select the person name >


班次1 中继器下拉列表1 中继器下拉菜单2 .

. 班次2 中继器下拉列表1 中继器下拉菜单2 .. . . 等

每件事都进行得很好,保存也很好

但问题是当我编辑移位表时。 因为我现在可以添加一个3人,在非特定时间之后添加另一个

因此,下拉列表应获取最后一个用户id并选择其值 我在加载主中继器时尝试了这段代码

protected void PrepareDropDownList(object sender, EventArgs e) 
    {
        Repeater repeater = (Repeater)sender;
        if (repeater.Items.Count > 0)
        {
            for (int shiftcount = 0; shiftcount < repeater.Items.Count; shiftcount++)
            {
                Repeater temp = (Repeater)repeater.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)); //a method to select a user with a specific id and add it to object from class sarcshiftuser

                        //ds.SelectedValue = user.user_id+"";
                        //ds.DataBind();
                        //err.Text += ds.SelectedValue + "<br />";
                        //if (user.id != 0)
                        //{
                        //    ds.SelectedIndex = ds.Items.IndexOf(ds.Items.FindByValue(user.user_id.ToString()));
                        //}

                    }
                }

            }
        }
    }
protectedvoid PrepareDropDownList(对象发送方,事件参数e)
{
中继器中继器=(中继器)发送器;
如果(repeater.Items.Count>0)
{
对于(int-shiftcount=0;shiftcount0)
{
对于(int count=0;count”;
//如果(user.id!=0)
//{
//ds.SelectedIndex=ds.Items.IndexOf(ds.Items.FindByValue(user.user\u id.ToString());
//}
}
}
}
}
}
但它不起作用,它需要正确的id,一切都很好,但dropdownlist没有 显示选定的值。。。我猜它的错误是因为findcontrol获取的是下拉列表的副本,而不是精确的副本


请帮助修复此代码或找到其他解决方案?

我使用了tooltip属性并调用此函数:

protected void PrepareDropDownList(object sender, EventArgs e)
    {
        DropDownList list = (DropDownList)sender;
        int i = int.Parse(list.ToolTip);
        "select the user_id where id ...." = id
        list.SelectedValue = user.user_id + "";
    }

<asp:DropDownList ID="userdropdown" CssClass="select" runat="server" OnDataBound="PrepareDropDownList" ToolTip='<%#Eval("repeaterid") %>' />
protectedvoid PrepareDropDownList(对象发送方,事件参数e)
{
DropDownList list=(DropDownList)发送方;
int i=int.Parse(list.ToolTip);
“选择用户id,其中id…”=id
list.SelectedValue=user.user_id+“”;
}

它起作用了。你不应该重复同样的问题。2.在您的问题中添加中继器的标记3。中继器的
onload
不是设置其dropdownlist值的最佳位置。可能重复