且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用中继器在数据库的下拉列表中显示值?

更新时间:2023-10-08 17:57:16

1)处理 DataBinding 事件

2)下拉列表的Items集合具有FindByValueFindByText方法之类的方法.使用它可以从下拉列表中获取ListItem.

3)将ListItem''s Selected属性设置为True
1) Handle the DataBinding event

2) Dropdown list''s Items collection has methods like FindByValue,FindByText methods. Using that you can get the ListItem from the dropdownlist.

3) Set the ListItem''s Selected property to True


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();