问题描述
我正在使用datalist控制使用C#和sqlserver 2008的asp.net。我在datalist中有一个下拉列表,需要在页面加载时显示数据库中的当前值。
i到目前为止已尝试过这个
I am using datalist control an asp.net using C# and sqlserver 2008.I have a dropdown in datalist and need to display it's current value from database on page load.
i have tried this so far
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item)
{DropDownList ddlshowit =(DropDownList)e。 Item.FindControl(DropDownList4);
ddlshowit.DataSource = ds;
ddlshowit.DataTextField =showit;
ddlshowit.DataValueField =showit;
ddlshowit.DataBind();
}
}
我也用过
SelectedValue ='<%#Eval(showit)%>'但它也没有用。请帮助
if (e.Item.ItemType == ListItemType.Item)
{ DropDownList ddlshowit = (DropDownList)e.Item.FindControl("DropDownList4");
ddlshowit.DataSource = ds;
ddlshowit.DataTextField = "showit";
ddlshowit.DataValueField = "showit";
ddlshowit.DataBind();
}
}
I also used
SelectedValue='<%#Eval("showit")%>' but it also did'nt work. Please Help
推荐答案
这篇关于如何将下拉列表绑定到数据库中存在的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!