FineUI 官方论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

本论坛已关闭(禁止注册、发帖和回复)
请移步 三石和他的朋友们

FineUI首页 WebForms - MVC & Core - JavaScript 常见问题 - QQ群 - 十周年征文活动

FineUI(开源版) 下载源代码 - 下载空项目 - 获取ExtJS - 文档 在线示例 - 版本更新 - 捐赠作者 - 教程

升级到 ASP.NET Core 3.1,快、快、快! 全新ASP.NET Core,比WebForms还简单! 欢迎加入【三石和他的朋友们】(基础版下载)

搜索
查看: 5705|回复: 6
打印 上一主题 下一主题

dropdownlist数据绑定的2个问题,希望高手能解答

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-25 11:53:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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:53 | 只看该作者
第1个问题解决了。。
this.DropDownList2.Items.Insert(0, new ExtAspNet.ListItem("=请选择姓名=", "0"));

这样可以了,第二个问题有待高手解答。
板凳
发表于 2012-9-25 12:53:11 | 只看该作者
'select * from...'改为select u_Labor_number,u_name from ....试一下
地板
 楼主| 发表于 2012-9-25 12:59:12 | 只看该作者
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

5#
发表于 2012-9-25 13:05:12 | 只看该作者
SystemN.ullReferenceException这个好像是有空值的,我也是初学
6#
 楼主| 发表于 2012-9-25 13:28:45 | 只看该作者
我知道,我已经写了,如果空值不执行吗。
7#
发表于 2012-9-29 08:00:31 | 只看该作者
有没有在页面加上"PageManager"
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|FineUI 官方论坛 ( 皖ICP备2021006167号-1 )

GMT+8, 2024-6-17 16:54 , Processed in 0.045884 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表