dropdownlist的INDEX值如何确定? 不行呀,我的代码是Label1.Text = cboItem.SelectedIndex & " KK " & cboItem.ID。我无论选哪个,cboItem.SelectedIndex都显示为0。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你在绑定的代码应该写在!IsPostBack函数里面 看你dropdownlist的是不是 runat=server 这样写DdlZ.Items[DdlZ.SelectedIndex].ValueDdlZ是dropdownlist 按照killerwc()提供的办法进行,得出嘅结果:cboItem.Items(cboItem.SelectedIndex).Value为空。如何是好啊? 同意 wurf0(wurf)的说法,你肯定把代码没有放在not page.ispostback里.每次刷新页面时便会重新绑定,所以为0啦. 我已经将代码改为以上,为何还不行呢?If Not IsPostBack Then Label1.Text = cboItem.Items(cboItem.SelectedIndex).Value & " KK " & cboItem.IDEnd If 将cboItem的AutoPostBack设为true;增加一个cboItem的SelectedIndexChanged事件private void cboItem_SelectedIndexChanged(object sender, System.EventArgs e){ Label1.Text = cboItem.SelectedIndex.ToString()& " KK " & cboItem.ID} 正如ameng_2002(树根)所写的那样去做,但都不行,选了cboitem中的某一项都不能让该项停留显示。我真的不知如何是好了。 你的DropDownList里面的数据是不是绑定的?绑定的在If Not IsPostBack Then End If里面绑定 代码如下:If Not IsPostBack Then Label1.Text = cboItem.Items(cboItem.SelectedIndex).Value & " KK " & cboItem.IDEnd IfcboItem的值我是通过程序一个一个add进去的。autopostback已经是true了。 <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" debug=true %><script runat="server">void Page_Load(object obj,EventArgs e){ if(!Page.IsPostBack) { string[] aaa={"aaa","bbb","ccc","ddd"}; dropDownList1.DataSource=aaa; dropDownList1.DataBind(); } else { label1.DataBind(); } }</script><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body><form runat="server"><asp:label id="label1" runat="server" text="<%# dropDownList1.Items[dropDownList1.SelectedIndex].Value %>"/><asp:dropdownlist id="dropDownList1" runat="server" AutoPostBack="true"/></form></body></html>测试通过,你看一下,我不清楚你要的是不是这个 把整个代码也贴出来吧!cboItem.Items(cboItem.SelectedIndex).Value也可以这样cboItem.SelectedItem.Value; 遇到正则表达式看不懂,请帮帮忙.. 控件做的通用导航菜单,如何取得cs的变更? asp.net如何访问其他虚拟目录中文件 向右对齐的一个链接 [现金]我实在弄晕了,关于搜索分7?在先等待... 为什么asp.net 2.0要搞成这样. 問個小問題 万分紧急,高分求字符串转换方法,在线等!! 十万火急!!! 关于类的问题,请高手指点迷津!! 感谢无名高手送我2000多分!!感激! 論壇中的回應
DdlZ.Items[DdlZ.SelectedIndex].Value
DdlZ是dropdownlist
If Not IsPostBack Then
Label1.Text = cboItem.Items(cboItem.SelectedIndex).Value & " KK " & cboItem.ID
End If
增加一个cboItem的SelectedIndexChanged事件
private void cboItem_SelectedIndexChanged(object sender, System.EventArgs e)
{
Label1.Text = cboItem.SelectedIndex.ToString()& " KK " & cboItem.ID
}
绑定的在If Not IsPostBack Then
End If
里面绑定
If Not IsPostBack Then
Label1.Text = cboItem.Items(cboItem.SelectedIndex).Value & " KK " & cboItem.ID
End If
cboItem的值我是通过程序一个一个add进去的。
autopostback已经是true了。
<script runat="server">
void Page_Load(object obj,EventArgs e)
{
if(!Page.IsPostBack)
{
string[] aaa={"aaa","bbb","ccc","ddd"};
dropDownList1.DataSource=aaa;
dropDownList1.DataBind();
}
else
{
label1.DataBind();
}
}
</script><html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form runat="server">
<asp:label id="label1" runat="server" text="<%# dropDownList1.Items[dropDownList1.SelectedIndex].Value %>"/>
<asp:dropdownlist id="dropDownList1" runat="server" AutoPostBack="true"/>
</form>
</body>
</html>测试通过,你看一下,我不清楚你要的是不是这个
cboItem.Items(cboItem.SelectedIndex).Value
也可以这样cboItem.SelectedItem.Value;