private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string deptSelect="select DeptName from AT_Dept";
string allEmployee="select UserName from AT_UserInformation1";
if(!IsPostBack)
{
ArrayList array=new ArrayList();
array.Add("请先选择部门");
array.Add("请选择职务");
RadioButtonList1.DataSource=array;
RadioButtonList1.DataBind();
RadioButtonList1.Items[0].Selected=true;
DataSet ds=new DataSet();
DataSet ds2=new DataSet();
try
{
SqlDataAdapter da=new SqlDataAdapter(deptSelect,sqlcon);
SqlDataAdapter da2=new SqlDataAdapter(allEmployee,sqlcon);
da.Fill(ds,"AT_Dept");
da2.Fill(ds2,"AT_UserInformation1");
DropDownList1.DataSource=ds.Tables["AT_Dept"].DefaultView;
DropDownList2.DataSource=ds2.Tables["AT_UserInformation1"].DefaultView;
DropDownList1.DataValueField="DeptName";
DropDownList2.DataValueField="UserName";
DropDownList1.DataBind();
DropDownList2.DataBind();
sqlcon.Close();
}
catch(System.Exception ex)
{
Console.WriteLine("the error:"+ex.Message.ToString());
}
finally
{
}
} } #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.DropDownList2.SelectedIndexChanged += new System.EventHandler(this.DropDownList2_SelectedIndexChanged);
this.RadioButtonList1.SelectedIndexChanged += new System.EventHandler(this.RadioButtonList1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
} private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
} private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string DutyName="";
string DeptName="";
string a=""; ArrayList DutyNameArray=new ArrayList();
//int i=1;
string dutySelect="select DeptName,DutyName from AT_Dept,AT_Duty where AT_Dept.DeptId=AT_Duty.DeptID";
SqlCommand cmd=new SqlCommand(dutySelect,sqlcon);
sqlcon.Open();
SqlDataReader rd=cmd.ExecuteReader();
while(rd.Read())
{
DeptName=rd.GetString(0);
DutyName=rd.GetString(1);
a=DeptName+"/"+DutyName;
DutyNameArray.Add(a);
}
sqlcon.Close();
for(int i=0;i<RadioButtonList1.Items.Count;i++)
if(RadioButtonList1.Items[1].Selected==true)
{
DropDownList1.Items.Clear();
DropDownList1.DataSource=DutyNameArray;
DropDownList1.DataBind();//我点RADIOBUTTONLIST1的第二个选项这里出问题
}
}
错误提示:
System.Web.HttpException: DataBinder.Eval:“System.String”不包含名称为 DeptName 的属性。源错误:
行 129: DropDownList1.Items.Clear();
行 130: DropDownList1.DataSource=DutyNameArray;
行 131: DropDownList1.DataBind();
行 132: }
行 133:
源文件: c:\inetpub\wwwroot\testmenu\chooseemployee.aspx.cs 行: 131
{
// 在此处放置用户代码以初始化页面
string deptSelect="select DeptName from AT_Dept";
string allEmployee="select UserName from AT_UserInformation1";
if(!IsPostBack)
{
ArrayList array=new ArrayList();
array.Add("请先选择部门");
array.Add("请选择职务");
RadioButtonList1.DataSource=array;
RadioButtonList1.DataBind();
RadioButtonList1.Items[0].Selected=true;
DataSet ds=new DataSet();
DataSet ds2=new DataSet();
try
{
SqlDataAdapter da=new SqlDataAdapter(deptSelect,sqlcon);
SqlDataAdapter da2=new SqlDataAdapter(allEmployee,sqlcon);
da.Fill(ds,"AT_Dept");
da2.Fill(ds2,"AT_UserInformation1");
DropDownList1.DataSource=ds.Tables["AT_Dept"].DefaultView;
DropDownList2.DataSource=ds2.Tables["AT_UserInformation1"].DefaultView;
DropDownList1.DataValueField="DeptName";
DropDownList2.DataValueField="UserName";
DropDownList1.DataBind();
DropDownList2.DataBind();
sqlcon.Close();
}
catch(System.Exception ex)
{
Console.WriteLine("the error:"+ex.Message.ToString());
}
finally
{
}
} } #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.DropDownList2.SelectedIndexChanged += new System.EventHandler(this.DropDownList2_SelectedIndexChanged);
this.RadioButtonList1.SelectedIndexChanged += new System.EventHandler(this.RadioButtonList1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
} private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
} private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string DutyName="";
string DeptName="";
string a=""; ArrayList DutyNameArray=new ArrayList();
//int i=1;
string dutySelect="select DeptName,DutyName from AT_Dept,AT_Duty where AT_Dept.DeptId=AT_Duty.DeptID";
SqlCommand cmd=new SqlCommand(dutySelect,sqlcon);
sqlcon.Open();
SqlDataReader rd=cmd.ExecuteReader();
while(rd.Read())
{
DeptName=rd.GetString(0);
DutyName=rd.GetString(1);
a=DeptName+"/"+DutyName;
DutyNameArray.Add(a);
}
sqlcon.Close();
for(int i=0;i<RadioButtonList1.Items.Count;i++)
if(RadioButtonList1.Items[1].Selected==true)
{
DropDownList1.Items.Clear();
DropDownList1.DataSource=DutyNameArray;
DropDownList1.DataBind();//我点RADIOBUTTONLIST1的第二个选项这里出问题
}
}
错误提示:
System.Web.HttpException: DataBinder.Eval:“System.String”不包含名称为 DeptName 的属性。源错误:
行 129: DropDownList1.Items.Clear();
行 130: DropDownList1.DataSource=DutyNameArray;
行 131: DropDownList1.DataBind();
行 132: }
行 133:
源文件: c:\inetpub\wwwroot\testmenu\chooseemployee.aspx.cs 行: 131
"select a.DeptName,b.DutyName from AT_Dept a inner join AT_Duty b on a.DeptId=b.DeptID";
select DeptName,DutyName from AT_Dept,AT_Duty where AT_Dept.DeptId=AT_Duty.DeptID
这个我查过没问题
只是管
System.String什么事啊
初始页面的下拉框
里面的DeptName都对的啊
2。datagrid里面没有这一列
单独写在一个页面上确没有问题
why?
private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string DutyName="";
string DeptName="";
string a=""; ArrayList DutyNameArray=new ArrayList();
//int i=1;
string dutySelect="select DeptName,DutyName from AT_Dept,AT_Duty where AT_Dept.DeptId=AT_Duty.DeptID";
SqlCommand cmd=new SqlCommand(dutySelect,sqlcon);
sqlcon.Open();
SqlDataReader rd=cmd.ExecuteReader();
while(rd.Read())
{
DeptName=rd.GetString(0);
DutyName=rd.GetString(1);
a=DeptName+"/"+DutyName;
DutyNameArray.Add(a);
}
sqlcon.Close();
for(int i=0;i<RadioButtonList1.Items.Count;i++)
if(RadioButtonList1.Items[1].Selected==true)
{
DropDownList1.Items.Clear();
DropDownList1.DataSource=DutyNameArray;
DropDownList1.DataBind();//我点RADIOBUTTONLIST1的第二个选项这里出问题
}
}