当前位置:  开发笔记 > 后端 > 正文

Repeater中DropDownList的SelectedValue

如何解决《Repeater中DropDownList的SelectedValue》经验,为你挑选了1个好方法。



1> Win..:

你快到了.你只需要转换DataItemDataRowView,并将其分配给DropDownList这样 -

protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || 
       e.Item.ItemType == ListItemType.AlternatingItem)
    {
        var degree_dropdown = e.Item.FindControl("degree_dropdown") as DropDownList;
        string degreeCode = (string) ((DataRowView) e.Item.DataItem)["degreeCode"];

        if (degree_dropdown != null)
        {
            degree_dropdown.DataSource = degrees; //a datatable
            degree_dropdown.DataTextField = "degree";
            degree_dropdown.DataValueField = "code";
            degree_dropdown.DataBind();

            if (degree_dropdown.Items.FindByValue(degreeCode) != null)
                degree_dropdown.SelectedValue = degreeCode;
        }
    }
}

推荐阅读
mobiledu2402852357
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有