using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Ex05_01_Ex05_07 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add("清华大学");
DropDownList1.Items.Add("北京大学");
DropDownList1.Items.Add("浙江大学");
Label1.Text = "网页第一次加载!";
Label2.Text = " ";
try
{
DropDownList2_content();
DropDownList3_content();
}
catch
{
Response.Write("<script language='javascript'>alert('连接失败!')</script>");
}
}
else
{
Label1.Text = "你选择的学校是: " + DropDownList1.SelectedItem.Text;
}
} protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList3_content();
if (ds.Tables["datatable"].Rows.Count != 0)
{
Label2.Text = DropDownList2.SelectedItem.Value + "数据库中的数据表" + DropDownList3.SelectedItem.Value;
}
else
{
Label2.Text = DropDownList2.SelectedItem.Value + "数据库中无用户数据表";
}
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
Label2.Text = DropDownList2.SelectedItem.Value + "数据库中的数据表" + DropDownList3.SelectedItem.Value;
}
}public class Ex05_04_02 : System.Web.UI.Page
{
public SqlConnection MyConnection;
public string strSQL;
public SqlDataAdapter myCommand;
public DataSet ds = new DataSet(); protected void DropDownList2_content()
{
MyConnection = new SqlConnection("server=localhost;usd=sa;pwd=;database=master");
strSQL = "select name from sysdatabases where dbid>=5 order by dbid desc";
myCommand = new SqlDataAdapter(strSQL, MyConnection);
myCommand.Fill(ds, "database");
DropDownList2.DataSource = ds.Tables["database"].DefaultView;
DropDownList2.DataValueField = ds.Tables["database"].Columns[0].ColumnName;
DropDownList2.DataTextField = ds.Tables["database"].Columns[0].ColumnName;
DropDownList2.DataBind();
}
protected void DropDownList3_content()
{
myConnection = new SqlConnection("server=localhost;uid=sa;pwd=;database=" + DropDownList2.SelectedItem.Value.ToString() + "");
strSQL = "select name from sysobjects where xtype='u' order by crdate desc";
myCommand = new SqlDataAdapter(strSQL, MyConnection);
myCommand.Fill(ds, "datatable");
DropDownList3.DataSource = ds.Tables["datatable"].DefaultView;
DropDownList3.DataValueField = ds.Tables["datatable"].Columns[0].ColumnName;
DropDownList3.DataTextField = ds.Tables["datatable"].Columns[0].ColumnName;
DropDownList3.DataBind();
}
}
错误提示:当前上下文中不存在名称“DropDownList2_content”
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Ex05_01_Ex05_07 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add("清华大学");
DropDownList1.Items.Add("北京大学");
DropDownList1.Items.Add("浙江大学");
Label1.Text = "网页第一次加载!";
Label2.Text = " ";
try
{
DropDownList2_content();
DropDownList3_content();
}
catch
{
Response.Write("<script language='javascript'>alert('连接失败!')</script>");
}
}
else
{
Label1.Text = "你选择的学校是: " + DropDownList1.SelectedItem.Text;
}
} protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList3_content();
if (ds.Tables["datatable"].Rows.Count != 0)
{
Label2.Text = DropDownList2.SelectedItem.Value + "数据库中的数据表" + DropDownList3.SelectedItem.Value;
}
else
{
Label2.Text = DropDownList2.SelectedItem.Value + "数据库中无用户数据表";
}
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
Label2.Text = DropDownList2.SelectedItem.Value + "数据库中的数据表" + DropDownList3.SelectedItem.Value;
}
}public class Ex05_04_02 : System.Web.UI.Page
{
public SqlConnection MyConnection;
public string strSQL;
public SqlDataAdapter myCommand;
public DataSet ds = new DataSet(); protected void DropDownList2_content()
{
MyConnection = new SqlConnection("server=localhost;usd=sa;pwd=;database=master");
strSQL = "select name from sysdatabases where dbid>=5 order by dbid desc";
myCommand = new SqlDataAdapter(strSQL, MyConnection);
myCommand.Fill(ds, "database");
DropDownList2.DataSource = ds.Tables["database"].DefaultView;
DropDownList2.DataValueField = ds.Tables["database"].Columns[0].ColumnName;
DropDownList2.DataTextField = ds.Tables["database"].Columns[0].ColumnName;
DropDownList2.DataBind();
}
protected void DropDownList3_content()
{
myConnection = new SqlConnection("server=localhost;uid=sa;pwd=;database=" + DropDownList2.SelectedItem.Value.ToString() + "");
strSQL = "select name from sysobjects where xtype='u' order by crdate desc";
myCommand = new SqlDataAdapter(strSQL, MyConnection);
myCommand.Fill(ds, "datatable");
DropDownList3.DataSource = ds.Tables["datatable"].DefaultView;
DropDownList3.DataValueField = ds.Tables["datatable"].Columns[0].ColumnName;
DropDownList3.DataTextField = ds.Tables["datatable"].Columns[0].ColumnName;
DropDownList3.DataBind();
}
}
错误提示:当前上下文中不存在名称“DropDownList2_content”
解决方案 »
- 如何将搜索结果显示在另一页面的GridView1控件里
- 第一次做Web安装程序,遇到以下几个问题,求助各位
- 小弟第一次做B/S系统,有几个问题想问一下各位大侠!~
- 问两个快捷键,谢谢!
- 关于ASP.net日历控件的问题
- 在gridview的模板列中如果访问DropDownList的值
- 上传大文件???????//
- ##--如何改变DataGrid的Item项的背景--###
- 使用FreeTextBox控件的问题:代码执行后插入数据库中没有内容,也没有任何错误提示?
- 我安装了VS.NET后。。。。
- 如何触发checkbox的事件?
- gridview中的如果commandname="select"会选黑,我添加多个linkbutton,其他commandname<>"select"怎么也让他选黑??
{
Label1.Text = "你选择的学校是: " + DropDownList1.SelectedItem.Text;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
----------
这里去掉一个"}"
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Ex05_01_Ex05_07 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add("清华大学");
DropDownList1.Items.Add("北京大学");
DropDownList1.Items.Add("浙江大学");
Label1.Text = "网页第一次加载!";
Label2.Text = " ";
try
{
DropDownList2_content();
DropDownList3_content();
}
catch
{
Response.Write("<script language='javascript'>alert('连接失败!')</script>");
}
}
else
{
Label1.Text = "你选择的学校是: " + DropDownList1.SelectedItem.Text;
}
} protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList3_content();
if (ds.Tables["datatable"].Rows.Count != 0)
{
Label2.Text = DropDownList2.SelectedItem.Value + "数据库中的数据表" + DropDownList3.SelectedItem.Value;
}
else
{
Label2.Text = DropDownList2.SelectedItem.Value + "数据库中无用户数据表";
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
Label2.Text = DropDownList2.SelectedItem.Value + "数据库中的数据表" + DropDownList3.SelectedItem.Value;
}
}public class Ex05_04_02 : System.Web.UI.Page
{
public SqlConnection MyConnection;
public string strSQL;
public SqlDataAdapter myCommand;
public DataSet ds = new DataSet(); protected void DropDownList2_content()
{
MyConnection = new SqlConnection("server=localhost;usd=sa;pwd=;database=master");
strSQL = "select name from sysdatabases where dbid>=5 order by dbid desc";
myCommand = new SqlDataAdapter(strSQL, MyConnection);
myCommand.Fill(ds, "database");
DropDownList2.DataSource = ds.Tables["database"].DefaultView;
DropDownList2.DataValueField = ds.Tables["database"].Columns[0].ColumnName;
DropDownList2.DataTextField = ds.Tables["database"].Columns[0].ColumnName;
DropDownList2.DataBind();
}
protected void DropDownList3_content()
{
myConnection = new SqlConnection("server=localhost;uid=sa;pwd=;database=" + DropDownList2.SelectedItem.Value.ToString() + "");
strSQL = "select name from sysobjects where xtype='u' order by crdate desc";
myCommand = new SqlDataAdapter(strSQL, MyConnection);
myCommand.Fill(ds, "datatable");
DropDownList3.DataSource = ds.Tables["datatable"].DefaultView;
DropDownList3.DataValueField = ds.Tables["datatable"].Columns[0].ColumnName;
DropDownList3.DataTextField = ds.Tables["datatable"].Columns[0].ColumnName;
DropDownList3.DataBind();
}
}
-----------
这样就可以了
不对,有语法错误。还是不通
这个类中,你调用了另一个类
public class Ex05_04_02 : System.Web.UI.Page这样恐怕不行吧。你在Ex05_01_Ex05_07 类中是 没有这个方法的
DropDownList2_content()
以下认识就是建立在上面的基础之上
不管错误不错误,我觉得你这样放置代码就是错误的
public class Ex05_04_02 : System.Web.UI.Page这个看你大部分的方法实际就是为了得到一个数据集然后和dropdownlist绑定,而这些dropdownlist是哪里的了?总体感觉你的代码很混乱