无法将类型“string”隐式转换为“System.Web.UI.WebControls.DropDownList

duzhe200910 2009-05-24 07:01:42
if (DropDownList1 = "管理员")
{
Response.Redirect("Index.aspx");
Session.Add("CardId",CardID);//
return;
}
else
{
Response.Redirect("HYIndex.aspx");
Session.Add("CardId",CardID);//
return;
}


这里出错,无法将类型“string”隐式转换为“System.Web.UI.WebControls.DropDownList,该怎么改呢,我DropDownList1里面数据就2个一个管理员,一个是会员
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
z522520 2009-05-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cxcco 的回复:]
if (DropDownList1 = "管理员")
这句错了。。。
应该是DropDownList.SelectedValue=="管理员"
[/Quote]
因该 就是 这么改吧
duzhe200910 2009-05-24
  • 打赏
  • 举报
回复
呵呵,感谢啊
我姓区不姓区 2009-05-24
  • 打赏
  • 举报
回复
if (DropDownList1.SelectedItem.Text == "管理员")
cxcco1986 2009-05-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lulinha 的回复:]
if (DropDownList1 = "管理员")
你这个红色的明显错啦,
用DropDownList1.SelectedValue = "管理员"试试
[/Quote]
在if语句中“=”是一个赋值操作。需要使用"=="
lulinha 2009-05-24
  • 打赏
  • 举报
回复
if (DropDownList1 = "管理员")
你这个红色的明显错啦,
用DropDownList1.SelectedValue = "管理员"试试
cxcco1986 2009-05-24
  • 打赏
  • 举报
回复
if (DropDownList1 = "管理员")
这句错了。。。
应该是DropDownList.SelectedValue=="管理员"
Ajax实现无刷新三联动下拉框 1.html代码 Ajax实现无刷新三联动下拉框
省市 dropdownlist id="DropDownList1" runat="server">dropdownlist>
城市 dropdownlist id="DropDownList2" runat="server">dropdownlist>
市区 dropdownlist id="DropDownList3" runat="server">dropdownlist>
2.cs代码 using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace AjaxTest { /**//// /// Summary description for WebForm1. /// public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.DropDownList DropDownList2; protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.DropDownList DropDownList3; private void Page_Load(object sender, System.EventArgs e) { Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethod)); if(!Page.IsPostBack) { this.DropDownList1.DataSource=AjaxMethod.GetProvinceList(); this.DropDownList1.DataTextField="province"; this.DropDownList1.DataValueField="provinceID"; this.DropDownList1.DataBind(); this.DropDownList1.Attributes.Add("onclick","cityResult();"); this.DropDownList2.Attributes.Add("onclick","areaResult();"); } } Web Form Designer generated code#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /**//// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }3.AjaxMethod using System; using System.Data; using System.Data.SqlClient; namespace AjaxTest { /**//// /// Summary description for AjaxMethod. /// public class AjaxMethod { GetProvinceList#region GetProvinceList public static DataSet GetProvinceList() { string sql="select * from province"; return GetDataSet(sql); } #endregion GetCityList#region GetCityList [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)] public DataSet GetCityList(int provinceid) { string sql="select * from city where father="+provinceid; return GetDataSet(sql); } #endregion GetAreaList#region GetAreaList [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)] public DataSet GetAreaList(int cityid) { string sql="select * from area where father="+cityid; return GetDataSet(sql); } #endregion GetDataSet#region GetDataSet public static DataSet GetDataSet(string sql) { string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; SqlDataAdapter sda =new SqlDataAdapter(sql,ConnectionString); DataSet ds=new DataSet(); sda.Fill(ds); return ds; } #endregion } }4.web.config
实现城市连动 using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; namespace _0327Province_City_代码实现_ { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string connstring = @"Data Source=.\SQLExpress;Initial Catalog=IDInfoDB;Integrated Security=True";//@表示转义字符 .\sqlexpress表示数据源 SqlConnection sconn = new SqlConnection(connstring); string Tablename = "province"; string selectstring = "select * from " + Tablename; SqlDataAdapter sda = new SqlDataAdapter(selectstring, sconn); DataSet ds = new DataSet(); sconn.Open(); sda.Fill(ds, Tablename); sconn.Close(); this.ddl_Province .DataSource = ds.Tables[Tablename].DefaultView; this.ddl_Province .DataTextField = "province"; this.ddl_Province .DataValueField = "provinceID"; this.ddl_Province .DataBind(); } } protected void ddl_City_SelectedIndexChanged(object sender, EventArgs e) { if (this.ddl_City .SelectedIndex >= 0) { string connstring = @"Data Source=.\SQLExpress;Initial Catalog=IDInfoDB;Integrated Security=True";//@表示转义字符 .\sqlexpress表示数据源 SqlConnection sconn = new SqlConnection(connstring); string Tablename = "area"; string selectstring = "select * from " + Tablename + " where cityid='" + this.ddl_City .SelectedValue + "'"; SqlDataAdapter sda = new SqlDataAdapter(selectstring, sconn); DataSet ds = new DataSet(); sconn.Open(); sda.Fill(ds, Tablename); sconn.Close(); this.ddl_Area .DataSource = ds.Tables[Tablename].DefaultView; this.ddl_Area .DataTextField = "area"; this.ddl_Area .DataValueField = "areaID"; this.ddl_Area .DataBind(); } } protected void ddl_Province_SelectedIndexChanged(object sender, EventArgs e) { if (this.ddl_Province .SelectedIndex >= 0) { string connstring = @"Data Source=.\SQLExpress;Initial Catalog=IDInfoDB;Integrated Security=True";//@表示转义字符 .\sqlexpress表示数据源 SqlConnection sconn = new SqlConnection(connstring); string Tablename = "city"; string selectstring = "select * from " + Tablename + " where provinceid='" + this.ddl_Province .SelectedValue + "'"; SqlDataAdapter sda = new SqlDataAdapter(selectstring, sconn); DataSet ds = new DataSet(); sconn.Open(); sda.Fill(ds, Tablename); sconn.Close(); this.ddl_City .DataSource = ds.Tables[Tablename].DefaultView; this.ddl_City .DataTextField = "city"; this.ddl_City .DataValueField = "cityID"; this.ddl_City .DataBind(); } } } }

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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