读书人

【提问】dropdownlist 不触发selected

发布时间: 2012-09-03 09:48:39 作者: rapoo

【提问】dropdownlist 不触发selectedindexchanged
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>内容管理系统</title>
<style>
body
{
scrollbar-base-color:#C0D586;
scrollbar-arrow-color:#FFFFFF;
scrollbar-shadow-color:DEEFC6;
}
</style>
</head>
<frameset rows="60,*" cols="*" frameborder="no" border="0" framespacing="0">
<frame src="top.aspx" name="topFrame" scrolling="no">
<frameset cols="180,*" name="btFrame" frameborder="NO" border="0" framespacing="0">
<frame src="menu.aspx" noresize name="menu" scrolling="yes">
<frame src="main.aspx" noresize name="main" scrolling="yes">
</frameset>
</frameset>
<noframes>
<body>您的浏览器不支持框架!</body>
</noframes>
</html>

在frameset的一边放了一个dropdownlist
然后在dropdownlist的selectedindexchanged里面写了些
代码,
可是调试的时候我去选择下拉框
它不会执行这个selectedindexchanged事件
这是为什么
难道和框架有原因?


[解决办法]
把dropdownlist的autopostback 改成true
[解决办法]
if(!ispostback)
{
bind();
}
autopostback=true;
估计可能是上面两个问题导致的吧
[解决办法]
绑定代码有问题吧
[解决办法]
你的选择索引改变事件!当它改变后得到一个下拉菜单的选项值!然后另一个控件得到这个值绑定就ok 了!回传设置为自动回传!
比如
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
int j = Convert.ToInt32(DropDownList1.SelectedValue.ToString());
string strWhere = " and s.shengid='" + j + "'";
ds = mbshi.GetList(strWhere);
DropDownList2.DataSource = ds;
DropDownList2.DataTextField = "shiname";
DropDownList2.DataValueField = "shiid";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem("<-选择->", "0"));
}
[解决办法]
我试了你的代码,是可以的。你在新建一个试试
[解决办法]
d
[解决办法]
设下断点吧,看在那一步出了问题的
[解决办法]
看好了
public void binddro1()
{
DataSet ds = new DataSet();
string strWhere = " ";
ds = mbsheng.GetList(strWhere);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "shengname";
DropDownList1.DataValueField = "shengid";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("<-选择->", "0"));
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
int j = Convert.ToInt32(DropDownList1.SelectedValue.ToString());
string strWhere = " and s.shengid='" + j + "'";
ds = mbshi.GetList(strWhere);
DropDownList2.DataSource = ds;
DropDownList2.DataTextField = "shiname";
DropDownList2.DataValueField = "shiid";


DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem("<-选择->", "0"));
}


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
binddro1();
}
}




[解决办法]
问题出现最大的两个地方,AutoPostBack设为true,另外一个就是page_load里面if (!IsPostBack)bind();
[解决办法]

探讨
看好了
    public void binddro1()
    {
        DataSet ds = new DataSet();
        string strWhere = "  ";
        ds = mbsheng.GetList(strWhere);
        DropDownList1.DataSource = ds;
        DropDownList1.DataTextField = "shengname";
        DropDownList1.DataValueField = "shengid";
        DropDownList1.DataBind();
        DropDownList1.Items.Insert(0, new ListItem(" <-选择->", "0"));
    }

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        int j = Convert.ToInt32(DropDownList1.SelectedValue.ToString());
        string strWhere = "  and  s.shengid='" + j + "'";
        ds = mbshi.GetList(strWhere);
        DropDownList2.DataSource = ds;
        DropDownList2.DataTextField = "shiname";
        DropDownList2.DataValueField = "shiid";
        DropDownList2.DataBind();
        DropDownList2.Items.Insert(0, new ListItem(" <-选择->", "0"));
    }


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
          binddro1();
        }
    }





[解决办法]
会不会是因为那些验证控件导致的。

[解决办法]
我给你的代码粘了下来 能跑。。
[解决办法]
框架中你能够使用Form吗?<form runat="server"> dropdownlist 没有在这里 , 你能执行到 那个事件 就怪了, 你应该好好研究一下 asp.net事件的原理 ! 尝试一下 使用别的办法吧。。

[解决办法]
我的回答 都35 楼了, 不知道 你们 没想到, 还是我的理解 本来就是错误的,请大家指点一二。。。。
[解决办法]
探讨
框架中你能够使用Form吗? <form runat="server">  dropdownlist  没有在这里 ,  你能执行到  那个事件  就怪了,  你应该好好研究一下  asp.net事件的原理  !    尝试一下 使用别的办法吧。。


[解决办法]
dropdownlist 是服务器控件吧, 服务器控件 是应该放在<form runat="server"> 中吧, 在一个普通的html 页面 能够使用 服务器控件?? 不知道你是怎么用的?
[解决办法]
autopostback属性设为true并且加上if(!IsPostBack){}

[解决办法]


把drowdownlist改成 <select></select>
[解决办法]

探讨
引用:
框架中你能够使用Form吗? <form runat="server">  dropdownlist  没有在这里 ,  你能执行到  那个事件  就怪了,   你应该好好研究一下  asp.net事件的原理   !    尝试一下 使用别的办法吧。。

可是有时候行有时候不行


[解决办法]
autopostback属性设为true并且加上if(!IsPostBack){}
[解决办法]
我发现是验证的问题。
我先把所有信息都给填上
再去拉那个下拉框会触发

[解决办法]
设个断点 F5不就知道了
[解决办法]
if(!ispostback)
{
bind();
}
autopostback=true;
估计可能是上面两个问题导致的吧

[解决办法]
支持一下

读书人网 >asp.net

热点推荐