如何编程设置DROPDOWNLIST中的SelectedValue时,它必然的XmlDataSource [英] How to programatically set SelectedValue of Dropdownlist when it is bound to XmlDataSource
本文介绍了如何编程设置DROPDOWNLIST中的SelectedValue时,它必然的XmlDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用的XmlDataSource
为数据源
为的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;
}
}
这篇关于如何编程设置DROPDOWNLIST中的SelectedValue时,它必然的XmlDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文