c#中dropdownlist二级联动问题,求大神指点啊,急啊

yebikong 2012-08-23 04:36:22
从网上搜了个dropdownlist二级联动,然后自己删减了下,把自己要的留下来,程序很OK。
现在想嵌套入自己的另外个网页,将其中两个dropdownlist设置成联动的,也就是 省-->市,选择省,会跳出相应的市。

显示错误,_default,成员名称不能与他们的封闭类型相同。

我知道是有 两个 public partial class _Default,但是我想把两个拼接起来,如何搞啊,就是又链接服务器又能实现二级联动功能,下面附上代码。
如何调整下啊



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySQLDriverCS;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
public MySQLConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
conn = new MySQLConnection(new MySQLConnectionString("127.0.0.1", "test", "root", "1234").AsString);
conn.Open();

if (!IsPostBack)
{
BindUser();
}

}


public partial class _Default: System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{

protected void Page_Load(object sender, EventArgs e)
{
string str = Page.ClientScript.GetCallbackEventReference(this, "arg", "test", null, false);///获取一个对客户端函数的引用
string script = "function callserver(arg){" + str + "}";///组织一个callserver函数
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "key", script, true);///注册客户端脚本
DropDownList5.Attributes.Add("onchange", "callserver(document.getElementById('DropDownList5').value)");///为DropDownList5添加客户端的onchange事件,触发callserver函数
}
#region ICallbackEventHandler
string selecttext = null;
public string GetCallbackResult()
{
StringBuilder sb = new StringBuilder();

if (selecttext == "Beijing")
{
sb.Append("Beijing");
}
else if (selecttext == "Shanghai")
{
sb.Append("Shanghai");
}
else if (selecttext == "Shaanxi")
{
sb.Append("Xian,Xianyang,Ankang,Hanzhong,Yanan,Weinan,Tongchuan,Yulin,Shangluo");
}


return sb.ToString();///给客户端函数test返回一个参数sb
}

public void RaiseCallbackEvent(string eventArgument)
{
selecttext = eventArgument;///获得客户端提交的参数赋给变量selecttext
}
#endregion

}



protected void btnSubmit_Click(object sender, EventArgs e)
{
string strFullname = txtFullname.Text;
string strShortname = txtShortname.Text;
string strAddress = txtAddress.Text;
string strCode = txtCode.Text;
string strperson = txtperson.Text;
string strDept = txtDept.Text;
string strPosition = txtPosition.Text;
string strTel = txtTel.Text;
string strFax = txtFax.Text;
string strPhone = txtPhone.Text;
string strMail = txtMail.Text;
string strWeb = txtWeb.Text;
string strReason = txtReason.Text;
string strdropdownlist1 = DropDownList1.Text;
string strdropdownlist2 = DropDownList2.Text;
string strdropdownlist3 = DropDownList3.Text;
string strdropdownlist4 = DropDownList4.Text;
string strdropdownlist5 = DropDownList5.Text;
string strdropdownlist6 = DropDownList6.Text;



new MySQLInsertCommand(conn, new object[,] { { "CompanyFullname", strFullname }, { "CompanyShortname", strShortname }, { "Industry", strdropdownlist1 }, { "Type", strdropdownlist2 }, { "Set_up_time", strdropdownlist3 }, { "Person", strdropdownlist4 }, { "Province", strdropdownlist5 }, { "District", strdropdownlist6 }, { "Address", strAddress }, { "Code", strCode }, { "Contact", strperson }, { "Dept", strDept }, { "Position", strPosition }, { "Telephone", strTel }, { "Fax", strFax }, { "Mobile_phone", strPhone }, { "Email", strMail }, { "Website", strWeb }, { "System_application", strAddress }, { "Reason", strReason }, { "Date", DateTime.Now.ToString() } }, "User_message");

BindUser();
}

public void BindUser()
{
DataTable dt = new MySQLSelectCommand(conn, new string[] { "CompanyFullname", "CompanyShortname", "Industry", "Address", "Code", "Contact", "Dept", "Position", "Telephone", "Fax", "Mobile_phone", "Email", "Website", "Date" }, new string[] { "User_message" }, null, null, null).Table;



}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{

}
protected void 用户协议_Click(object sender, EventArgs e)
{
Response.Write(" <script> window.open( 'http://www.hr-channel.com '); </script> ");
}


}




...全文
163 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yebikong 2012-08-24
  • 打赏
  • 举报
回复
求如何修改呀,如何合并一个页面呢
yebikong 2012-08-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
很显然,名称相同了

public partial class _Default : System.Web.UI.Page
这里修改成对应的页面的名称
[/Quote]

但是我是在一个页面里呀,两个是共一个页面的
xieyonjie 2012-08-24
  • 打赏
  • 举报
回复
你这都不是从数据库取吗?
可以做成联动查询..绑定级联的。
  • 打赏
  • 举报
回复
直接把代码复制到相应的方法中就可以了,或者重构成单独的方法,一起调用
  • 打赏
  • 举报
回复
很显然,名称相同了

public partial class _Default : System.Web.UI.Page
这里修改成对应的页面的名称
yebikong 2012-08-23
  • 打赏
  • 举报
回复
顶啊,求大神出现啊,我新手

62,046

社区成员

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

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

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

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