FineUI 官方论坛
标题:
dropdownlist数据绑定的2个问题,希望高手能解答
[打印本页]
作者:
の‵℡閊鳮﹌
时间:
2012-9-25 11:53
标题:
dropdownlist数据绑定的2个问题,希望高手能解答
1、用数据库绑定的插入首行的问题
后台代码:
private void DownBind1()
{
//默认显示分类号为1的所有子类
string dda = "";
if (Session["u_qy"].ToString() == "1")
{
dda = "select * from tbType where u_qy='1' order by u_team";
}
else if (Session["u_qy"].ToString() == "2")
{
dda = "select * from tbType where u_qy='2' order by u_team";
}
DataTable mytab = this.Get_Dt2(dda);
this.DropDownList1.DataSource = mytab;
this.DropDownList1.DataValueField = "u_team";
this.DropDownList1.DataTextField = "u_team";
this.DropDownList1.DataBind();
//添加一个"请选择"行
this.DropDownList1.Items.Insert(0, new ListItem("请选择分类", ""));
}
提示错误信息:
编译器错误消息:
CS1502: 与“System.Collections.ObjectModel.Collection<ExtAspNet.ListItem>.Insert(int, ExtAspNet.ListItem)”最匹配的重载方法具有一些无效参数
不知道为什么不行,但官方示例那个省市联动是可以的。请求答案。
2、绑定DropDownList1之后,要利用DropDownList1_SelectedIndexChanged事件联动DropDownList2,也是根据数据库绑定的。但不行,弹出框框提示 Internal Error(500),且提示未将对象实例化。
后台代码:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem != null)
{
string dda = "";
if (Session["u_qy"].ToString() == "1")
{
if (Session["u_jn"].ToString() == "四区动感")
{
dda = "select * from OT_user_table where u_team='" + this.DropDownList1.SelectedValue + "' and u_jn='四区动感' and u_name!='" + Session["u_name"].ToString() + "' order by u_name ";
}
else if (Session["u_jn"].ToString() == "四区神")
{
dda = "select * from OT_user_table where u_team='" + this.DropDownList1.SelectedValue + "' and u_jn='四区神' and u_name!='" + Session["u_name"].ToString() + "' order by u_name ";
}
else if (Session["u_jn"].ToString() == "江湛动神" || Session["u_jn"].ToString() == "江湛神")
{
dda = "select * from OT_user_table where u_team='" + this.DropDownList1.SelectedValue + "' and (u_jn='江湛动神' or u_jn='江湛神') and u_name!='" + Session["u_name"].ToString() + "' order by u_name";
}
else
{
dda = "select * from OT_user_table where u_team='" + this.DropDownList1.SelectedValue + "' and u_jn='" + Session["u_jn"] + "' and u_name!='" + Session["u_name"].ToString() + "' order by u_name ";
}
}
else if (Session["u_qy"].ToString() == "2")
{
string aaaa = Session["u_jn"].ToString();
if (Session["u_jn"].ToString() == "复合全球通")
{
dda = "select * from OT_user_table where u_team='" + this.DropDownList1.SelectedValue + "' and u_jn='复合全球通' and u_name!='" + Session["u_name"].ToString() + "' order by u_name ";
}
else if (Session["u_jn"].ToString() == "四区全球通")
{
dda = "select * from OT_user_table where u_team='" + this.DropDownList1.SelectedValue + "' and u_jn='四区全球通' and u_name!='" + Session["u_name"].ToString() + "' order by u_team,u_jn ";
}
else
{
dda = "select * from OT_user_table where u_zg='2' and (u_qy='1' or u_qy='2') and u_team='" + this.DropDownList1.SelectedValue + "' and u_jn='" + Session["jn"] + "' and u_name!='" + Session["u_name"].ToString() + "' order by u_team,u_jn ";
}
}
this.DropDownList2.DataSource = Get_Dt(dda);
this.DropDownList2.DataValueField = "u_Labor_number";
this.DropDownList2.DataTextField = "u_name";
this.DropDownList2.DataBind();
//this.ddlMsg.Items.Insert(0, new ListItem("=请选择姓名=", "0"));
}
}
请求各位高手解决我的传值问题。本人菜鸟,初学者!
作者:
の‵℡閊鳮﹌
时间:
2012-9-25 12:24
第1个问题解决了。。
this.DropDownList2.Items.Insert(0, new
ExtAspNet
.ListItem("=请选择姓名=", "0"));
这样可以了,第二个问题有待高手解答。
作者:
yygy
时间:
2012-9-25 12:53
'select * from...'改为select u_Labor_number,u_name from ....试一下
作者:
の‵℡閊鳮﹌
时间:
2012-9-25 12:59
yygy 发表于 2012-9-25 12:53
'select * from...'改为select u_Labor_number,u_name from ....试一下
还是一样喔。。。
还是提示:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
ExtAspNet.ControlBase.RecoverPropertiesFromJObject(JObject state) +667
ExtAspNet.ControlBase.OnInit(EventArgs e) +102
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Page.ProcessRequestMain(Boolean includeStages
作者:
yygy
时间:
2012-9-25 13:05
SystemN.ullReferenceException这个好像是有空值的,我也是初学
作者:
の‵℡閊鳮﹌
时间:
2012-9-25 13:28
我知道,我已经写了,如果空值不执行吗。
作者:
yygy
时间:
2012-9-29 08:00
有没有在页面加上"PageManager"
欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/)
Powered by Discuz! X3.4