怎么给reapter 里的dropdownlist 赋值?
解决方案 »
- C# Global.asax 应用类问题
- (未处理SocketException)远程主机强迫关闭了一个现有的连接。
- 格式化字符串的问题
- 利用XML实现通用WEB报表打印,谁做过?
- 关于asp.net网站发布的问题,知识性问题
- 一个Linq问题。实体在层间传递
- 怎样在读取SQL Server 2000数据后,在Web页面上画曲线图
- 上个星期网站被黑了以后,我做了以下改进,请看行不行?
- 水晶报表有没有根据数据动态生成网格的功能?
- **********我的javascript输出为什么总是在html之外***************
- 急求:ASP.NET中如何对网页的访问进行IP地址限制?
- SQL 去重复问题
使用FindControl方法找到DropDownList控件,然后根据你的条件绑定就行了。
2、使用数据源控件
{ BindData();}
<asp:repeater id="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<itemtemplate>
<div>
<asp:dropdownlist id="ddl" autopostback="true" onselectedindexchanged="myDrop_SelectedIndexChanged" runat="server"> </asp:dropdownlist>
</div>
</itemtemplate>
</asp:repeater> protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
{
DropDownList myDrop = e.Item.FindControl("ddl") as DropDownList;
}
} protected void myDrop_SelectedIndexChanged(object sender,EventArgs e)
{
Response.Write(((DropDownList)sender).SelectedIndex.ToString());
}
this.rep.DataSource = ...;//绑定Repeater
this.rep.DataBind();
for (int i = 0; i < this.rep.Items.Count; i++)
{
获得rep中的姓名
DropDownList drop = (DropDownList)this.rep.Items[i].FindControl("dropdownlist控件名");
drop.DataSource = ...//获得数据 drop.DataValueField = "renName";
drop.DataTextField = "renName";
drop.DataBind();
}