有没办法在服务端让dropdownlist不选择

ttyp 2004-11-22 08:44:26
DropDownList1.Items.Add(new ListItem("1","1"));
DropDownList1.Items.Add(new ListItem("2","2"));
DropDownList1.Items.Add(new ListItem("3","3"));

DropDownList1.SelectedIndex = -1;

//现在只能通过js来实现了
...全文
159 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenyuming2004 2004-11-22
  • 打赏
  • 举报
回复
if(!IsPostBack)
{
DropDownList1.Items.Add(new ListItem("1","1"));
DropDownList1.Items.Add(new ListItem("2","2"));
DropDownList1.Items.Add(new ListItem("3","3"));
Response.Write("<script language=\"javascript\">"
+"DropDownList1.selectedIndex=-1;"
+"</script>");
}
这样写虽然效果不好。
gui1401 2004-11-22
  • 打赏
  • 举报
回复
DropDownList1.Items.SelectedItem.Selected = false;
baobaofall 2004-11-22
  • 打赏
  • 举报
回复
DropDownList1.Items.Insert(0,new ListItem("",""));


完全正确
ttyp 2004-11-22
  • 打赏
  • 举报
回复
dropdownlist.selecteditem.text=""
改写了第一个条目

DropDownList1.Items.Insert(0,new ListItem("",""));
不行,因为要在js里判断其SelectedIndex

就奇怪js里能改,服务端为什么不能改呢
colinliu 2004-11-22
  • 打赏
  • 举报
回复
dropdownlist.selecteditem.text=""

或上邊的方法也可以....
zhengjianning402 2004-11-22
  • 打赏
  • 举报
回复
DropDownList1.Items.Insert(0,new ListItem("",""));
同意
saucer 2004-11-22
  • 打赏
  • 举报
回复
it is the browser issue, the browser will select the first one if none is selected, try to add an empty ListItem at the top or use javascript


DropDownList1.Items.Insert(0,new ListItem("",""));
learner01 2004-11-22
  • 打赏
  • 举报
回复
up!
goody9807 2004-11-22
  • 打赏
  • 举报
回复
DropDownList1.Enable=false
ttyp 2004-11-22
  • 打赏
  • 举报
回复
楼上几位测试下吧,看来是没办法了

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧