下拉列表默认值
我的 WebUserControl 上有一对 ddlist。在我的 Page_Load 代码中,我输入了:
ddlDay.Items.Insert(0, new ListItem("Day", "0"));
ddlMonth.Items.Insert(0, new ListItem("Month", "0"));
CatalogAccess ca = new CatalogAccess();
ddlStudents.Items.Insert(0, new ListItem("Choose", "0"));
ddlStudents.DataSource = ca.GetStudents();
ddlStudents.DataTextField = "FullName";
ddlStudents.DataValueField = "UserID";
ddlStudents.DataBind();
它对于这些未数据绑定的 ddl 效果很好。这个>
ddlStudents.Items.Insert(0, new ListItem("Choose", "0"));
根本不起作用。每次我只得到学生的名字。如何解决这个问题。
There's a pair of ddlists on my WebUserControl. In My Page_Load code I have typed:
ddlDay.Items.Insert(0, new ListItem("Day", "0"));
ddlMonth.Items.Insert(0, new ListItem("Month", "0"));
CatalogAccess ca = new CatalogAccess();
ddlStudents.Items.Insert(0, new ListItem("Choose", "0"));
ddlStudents.DataSource = ca.GetStudents();
ddlStudents.DataTextField = "FullName";
ddlStudents.DataValueField = "UserID";
ddlStudents.DataBind();
It works good to these ddl which are not databined. This one >
ddlStudents.Items.Insert(0, new ListItem("Choose", "0"));
doesnt work at all. Every time I am getting just the names of the students. How to fix this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要在
ddlStudents
下拉列表中设置AppendDataBoundItems="true"
。You need to set
AppendDataBoundItems="true"
on yourddlStudents
dropdown.我相信您还应该能够在数据绑定之后移动空白行的插入。
希望这有帮助。
I believe that you should also be able to move the insert of the blank row after the databind.
Hope this helps.
您可以通过 ca.GetStudents() 返回的 Students 集合。
You can through the collection of Students that ca.GetStudents() returns.