gpt4 book ai didi

c# - 为什么不能选择 DropDownList 项?

转载 作者:太空宇宙 更新时间:2023-11-03 12:18:39 25 4
gpt4 key购买 nike

当我用FineUI DropDownList实现一棵树的时候。页面源代码如下:

    <form id="form1" runat="server">
<div>
<FineUI:PageManager runat="server" id="PageManager1"></FineUI:PageManager>
<FineUI:SimpleForm ID="SimpleForm1" BodyPadding="5px" runat="server" LabelWidth="150px" Width="550px" EnableCollapse="true"
ShowBorder="True" Title="Simple Form" ShowHeader="True">
<Items>
<FineUI:DropDownList Label="Simulation tree DropDownList" AutoPostBack="false" Required="true" EnableSimulateTree="true"
ShowRedStar="true" runat="server" ID="ddlBox">
</FineUI:DropDownList>
<FineUI:Button ID="Button1" Text="Show Selected Item" runat="server" OnClick="Button1_Click">
</FineUI:Button>
<FineUI:Label runat="server" ID ="result" Label ="select items"></FineUI:Label>
</Items>
</FineUI:SimpleForm>
</div>
</form>

在 page_load() 事件中完成 DropDownList 的数据绑定(bind)。事件代码:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
binddata();
}
}
public class JQueryFeature
{
private string _id;
public string Id
{
get { return _id; }
set { _id = value; }
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private int _level;
public int Level
{
get { return _level; }
set { _level = value; }
}
private bool _enableSelect;
public bool EnableSelect
{
get { return _enableSelect; }
set { _enableSelect = value; }
}
public JQueryFeature(string id, string name, int level, bool enableSelect)
{
_id = id;
_name = name;
_level = level;
_enableSelect = enableSelect;
}
public override string ToString()
{
return String.Format("Name:{0}+Id:{1}", Name, Id);
}
}
private void binddata()
{
List<JQueryFeature> mylist= new List<JQueryFeature>();
mylist.Add(new JQueryFeature("0", "jQuery", 0, false));
mylist.Add(new JQueryFeature("1", "core", 1, false));
mylist.Add(new JQueryFeature("2", "Select", 1, false));
mylist.Add(new JQueryFeature("3", "Base Select", 2, true));
mylist.Add(new JQueryFeature("4", "Content Select", 2, true));
mylist.Add(new JQueryFeature("5", "Property Select", 2, true));
mylist.Add(new JQueryFeature("6", "Sift", 1, false));
mylist.Add(new JQueryFeature("7", "Filtration", 2, true));
mylist.Add(new JQueryFeature("8", "Search", 2, true));
mylist.Add(new JQueryFeature("9", "Event", 1, false));
mylist.Add(new JQueryFeature("10", "Page_load", 2, true));
mylist.Add(new JQueryFeature("11", "Event_deal", 2, true));
mylist.Add(new JQueryFeature("12", "Event_authorize", 2, true));
ddlBox.DataTextField = "Name";
ddlBox.DataValueField = "Id";
ddlBox.DataSimulateTreeLevelField = "Level";
ddlBox.DataEnableSelectField = "EnableSelect";
ddlBox.DataSource = mylist;
ddlBox.DataBind();
}

当我完成这些代码时。 DropDownList 可以显示数据,但是有一个问题我无法选择列表中的任何项目。我该如何解决这个问题?

最佳答案

设置 DropDownList 的 SelectedValue。在 binddata() 事件的末尾添加此代码:ddlBox.SelectedValue = "3";问题会解决。

关于c# - 为什么不能选择 DropDownList 项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48535562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com