绑定到XmlDataSource时如何以编程方式设置Dropdownlist的SelectedValue [英] How to programmatically set SelectedValue of Dropdownlist when it is bound to XmlDataSource
本文介绍了绑定到XmlDataSource时如何以编程方式设置Dropdownlist的SelectedValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 XmlDataSource
作为 dropdownlist
的 datasource
.
I'm using XmlDataSource
as the datasource
for a dropdownlist
.
现在我想在页面最初加载时设置下拉菜单的 SelectedValue
.我已经尝试了下拉菜单的 OnDataBound 事件
,我可以在其中看到总项目数.但是设置 SelectedValue
不起作用.在OnDataBinding
事件中,我什至看不到总项目数,可能是因为列表尚未绑定?
Now I want to set the SelectedValue
of the drop down when the page initially loads. I have tried the OnDataBound event
of the drop down in which I could see the total items. But setting the SelectedValue
didn't work. InOnDataBinding
event, I couldn't even see the total items probably because the list isn't bound yet?
如何根据值设置所选索引?
How can I set the selected index based on a value?
推荐答案
这似乎对我有用.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.DataBind(); // get the data into the list you can set it
DropDownList1.Items.FindByValue("SOMECREDITPROBLEMS").Selected = true;
}
}
这篇关于绑定到XmlDataSource时如何以编程方式设置Dropdownlist的SelectedValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文