<asp:DropDownList id="ddlclass" runat="server" Width=200
onChange="clange_class(document.Form1.ddlclass.options[document.Form1.ddlclass.selectedIndex].value)" AutoPostBack=true></asp:DropDownList>
小类:<asp:DropDownList id="ddlitem" runat="server" Width="200px"></asp:DropDownList>protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
WriteScript();
bind_class();
bind_item();
}
}在点解ie的刷新按钮后,DropDownList没有选项了
onChange="clange_class(document.Form1.ddlclass.options[document.Form1.ddlclass.selectedIndex].value)" AutoPostBack=true></asp:DropDownList>
小类:<asp:DropDownList id="ddlitem" runat="server" Width="200px"></asp:DropDownList>protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
WriteScript();
bind_class();
bind_item();
}
}在点解ie的刷新按钮后,DropDownList没有选项了
解决方案 »
- [史上最菜星高分求助]sl中Gridview多行表头原样导出Excel,期待牛人
- 在GridView里显示表情,怎么做?
- 急,我将一个pdf文件上传到数据库为二进制文件,我如何再把它读出来呀!急~~将数据库的二进制pdf文件读出?
- 装vs.net的烦恼,望大侠帮助解决。
- 如何动态添加RadioButtonList控件啊?谢谢 !!
- 请教高手一个底层点的问题:如何写入流数据到指定web控件?请指点啊。。。
- 请问这个查询语句怎么写? 最好用存储过程 谢谢!
- 点击一个按钮,如何弹出一个窗体?
- 关于用户认证签名证书
- 请问NET是以XML为核心那么到底XML有什么特别呢 ?
- 在updatepanel中使用cuteEditor控件,更新后cuteEditor变成了不可用状态
- AutoCompleteExtender选中后能完成另一个事件怎么做
这个方法是绑定dropdownlist的方法吗?
没有联动吧?
{
ddlclass.DataSource = db_query.OpenQuery("select ClassID, CLassName from tb_class");
ddlclass.DataValueField = "ClassID";
ddlclass.DataTextField = "ClassName";
ddlclass.DataBind();
} void bind_item()
{
if (ddlclass.SelectedItem == null)
{
return;
} ddlitem.DataSource = db_query.OpenQuery("select ID, ItemName from tb_item where ClassID=" + Convert.ToUInt32(ddlclass.SelectedValue));
ddlitem.DataValueField = "ID";
ddlitem.DataTextField = "ItemName";
ddlitem.DataBind();
}
{
WriteScript();
bind_class();
bind_item();
}
ddlitem 这个没了?
为什么不用调试看一下 ddlclass.SelectedValue 的值呢?
是否删除了
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddl" runat="server" Width="15%" AutoPostBack="True" OnSelectedIndexChanged="ddl_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlChild" runat="server" Width="20%">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
clange_class(document.Form1.ddlclass.options[document.Form1.ddlclass.selectedIndex].value);
</script>放在你页面最底下。
if (!IsPostBack)
{
WriteScript();
bind_class();
}
我不知道你哪个方法是绑定下拉框的,估计是bind_item()
那么你就必须自己写(网站里成千上万个)任何维系视图状态的代码。否则,就学asp编程或者asp.net mvc编程,不要学asp.net webform编程。
<tr>
<td>
大 类:
<asp:DropDownList id="ddlclass" runat="server" Width=200
onChange="clange_class(document.Form1.ddlclass.options[document.Form1.ddlclass.selectedIndex].value)" EnableViewState=true></asp:DropDownList>
小 类:<asp:DropDownList id="ddlitem" runat="server" Width="200px" EnableViewState=true></asp:DropDownList>
</td>
</tr>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
WriteScript();
bind_class();
bind_item();
}
} private void WriteScript()
{
string str_sql = "select * from tb_item";
string scriptString = get_class_change_script(str_sql, "ItemName", "ID", "ClassID", ddlitem.ID); if (!ClientScript.IsClientScriptBlockRegistered("clientScript"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", scriptString);
}
} void bind_class()
{
this.ddlclass.DataSource = db_query.OpenQuery("select ClassID, CLassName from tb_class");
this.ddlclass.DataValueField = "ClassID";
this.ddlclass.DataTextField = "ClassName";
this.ddlclass.DataBind();
} void bind_item()
{
if (this.ddlclass.SelectedItem == null)
{
return;
} this.ddlitem.DataSource = db_query.OpenQuery("select ID, ItemName from
tb_item where ClassID=" + Convert.ToUInt32(ddlclass.SelectedValue));
this.ddlitem.DataValueField = "ID";
this.ddlitem.DataTextField = "ItemName";
this.ddlitem.DataBind();
}
public static string get_class_change_script(string str_sql, string x_c_str, string x_c_id, string d_c_id, string x_id_name)
{
int count = 0;
string scriptString = "<Script Language=JavaScript>\n var onecount;";
scriptString += "\n onecount=0;";
scriptString += "\n subcat=new Array();"; DataTable dt = db_query.OpenQuery(str_sql); for (int i = 0; i < dt.Rows.Count; ++i)
{
scriptString += "\n subcat[" + count + "]=new Array(" + "'" + dt.Rows[i][x_c_str] + "'" + "," + "'"
+ dt.Rows[i][d_c_id] + "'" + "," + "'" + dt.Rows[i][x_c_id] + "'" + ");";
count++;
} scriptString += "\n onecount=" + count + ";";
scriptString += "\n function clange_class(class_id){";
scriptString += "\n document.Form1." + x_id_name + ".length = 0;";
scriptString += "\n var class_id=class_id;";
scriptString += "\n var i;";
scriptString += "\n for(i=0; i<onecount; i++){";
scriptString += "\n if(subcat[i][1]==class_id){";
scriptString += "\n document.Form1." + x_id_name + ".options[document.Form1." + x_id_name + ".length]=new Option(subcat[i][0],subcat[i][2]);";
scriptString += "\n }";
scriptString += "\n }";
scriptString += "\n }";
scriptString += "</script>"; return scriptString;
}刷新的问题解决,主要是在vs2008的测试服务器不可以,is中可以。
现在主要是提交的时候报错,各位帮忙,分不够再加
各位高手帮帮忙