如何使用中继器在数据库的下拉列表中显示值? [英] How to display a value in drop down list from database using repeater?
本文介绍了如何使用中继器在数据库的下拉列表中显示值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我是这个领域的新手,请帮帮我.
我想显示从数据库表到asp.net控件的值,如文本框等.使用转发器,我在控件中显示所有值.现在,我想在dropdownlist中显示一个值作为选定值.该怎么办?
请帮帮我......
Hi guys,
I am new to this field so please help me out.
I want to display value from database table to asp.net controls lik textbox etc.... Using repeater i am displaying all values in controls .Now i want to display a value as selected value in dropdownlist . What to do?
Please help me guys......
推荐答案
1)处理DataBinding
事件
2)下拉列表的Items集合具有FindByValue
,FindByText
方法之类的方法.使用它可以从下拉列表中获取ListItem
.
3)将ListItem''s Selected
属性设置为True
1) Handle theDataBinding
event
2) Dropdown list''s Items collection has methods likeFindByValue
,FindByText
methods. Using that you can get theListItem
from the dropdownlist.
3) Set theListItem''s Selected
property toTrue
Hi,
试试这个
Hi,
try this
<asp:Repeater ID="Rep" runat="server" OnItemDataBound="rep_ItemDataBound">
<ItemTemplate>
<table width="100%">
<tr>
<td valign="top" width="13%" align="left">
<asp:DropDownList ID="Dropdown1" runat="server" Width="80px">
</asp:DropDownList>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
//in the code behind section
in the repDataBound Event find that drop down and bind it
DropDownList myDD = (DropDownList)e.Item.FindControl("Dropdown1");
myDD.DataTextField = "Name";
myDD.DataValueField = "Id";
myDD.DataBind();
这篇关于如何使用中继器在数据库的下拉列表中显示值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文