方法一:
可以在前台设置DropDownList的DataSource方法二:
在后台的ItemDataBound事件中绑定
可以在前台设置DropDownList的DataSource方法二:
在后台的ItemDataBound事件中绑定
解决方案 »
- 欢迎来讨论。MVC视图调用实体
- |zyciis|第三贴:SSL的数据提交:远程服务器返回错误: (403) 已禁止 现在只能把IIS应用缓存池的标识从网络服务改为本地系统 有其服办法吗
- 使用模板页的变量
- dataset的问题
- 给用户控件上的Label1传值
- repeater 三列显示
- 如何去掉Calendar必须放在form标签里的限制
- 请大虾帮看看关于DataGrid的ItemDataBound事件的问题!谢谢
- 这样的效果如何实现? http://arts.tom.com/1002/2005624-21904.html
- 看一个页传递语句解释
- aspnetdb数据库难题,思归,孟子老师请进~
- 动态加载弹出菜单
{
DropDownList dropTemp;
string strState;
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
strState = ((DataRowView)e.Item.DataItem).Row["state"].ToString(); //对DropDownList做数据绑定
dropTemp = (DropDownList)e.Item.FindControl("DropDownList1");
if(dropTemp != null)
{
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
string strSql = "select distinct state from authors";
SqlCommand cmd = new SqlCommand(strSql, cn);
cn.Open();
dropTemp.DataSource = cmd.ExecuteReader();
dropTemp.DataTextField = "state";
dropTemp.DataBind();
cn.Close(); //到DropDownList中根据type的值去找需要设置为选中状态的项目,将其设置为选中
ListItem item = dropTemp.Items.FindByText(strState);
if(item != null)
{
item.Selected = true;
}
}
}
}
那么就再弄一个datasource 然后绑定到dropdownlist 就好饿
Request["DropDownList1"].Trim().ToString()能获取吗?
DropDownList drp = item.FindControl("DropDownList1") as DropDownList;
if(drp != null) {
string val = drp.SelectedValue;
// ....
}
}
{
DropDownList drp = e.Item.FindControl("DropDownList1") as DropDownList;
if(drp != null) {
string val = drp.SelectedValue;
// ....
}
}
=================================
客户端还是服务器端?如果是服务器端要入楼上对遍历
string sql = "select DepName from DepInfo order by DepName";
DB db = new DB(strcon);
DataTable dt = db.GetDataTable(sql); ListItem lst = new ListItem();
lst.Text = "Please select";
ddl_dep.Items.Add(lst);//dropdownlist
for (int i = 0; i < dt.Rows.Count; i++)//fill the data into the dropdownlist
{
ddl_dep.Items.Add(dt.Rows[i][0].ToString());
}
this.ddl_dep.SelectedIndex = 0;