if (Request.QueryString.Count != 0)
        {
            String NewsSortID = Request.QueryString["NewsSortID"].ToString();
            NewsSort newSort = new NewsSort();
            DataSet ds= newSort.queryNewsSortInfoId(NewsSortID);
            if (ds.Tables[0].Rows.Count == 1 || ds.Tables[0].Rows.Count == 0)
            {
                this.Button3.Visible = false;
                this.TextBox1.Visible = false;
                this.DropDownList1.Visible = false;
            }
            
            
                this.DropDownList1.DataSource = ds;
                
                this.DropDownList1.DataBind();
这是这样绑定的!
但页面会被刷新事件不会被执行。。
如果我DropDownList1不这样磅定我的事件就会被触发救救小弟啊`

解决方案 »

  1.   

    1、autopostback = true2、这些个if都true么?- -;
      

  2.   

    绑定的代码要放到!ispostback里
      

  3.   

    autopostback = true 
      

  4.   

    autopostback = true 
    绑定的代码要放到!ispostback里貌似就是这个原因
      

  5.   

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1" DataTextField="Name" DataValueField="ClassID">
                    </asp:DropDownList>                  if(!this.IsPostBack){
                this.start();
                this.bingDropDownList1();
            }        我都这样写`但就是不行`如果没有那磅定事件就会激活`    
      

  6.   

    断点
    断到
                  if(!this.IsPostBack){ 
                this.start(); 
                this.bingDropDownList1(); 
            }        
    这个}位置就没了
    唉!!
      

  7.   

    //数据库
       public DataSet FillDS(string sql)
            {
                GetConn getConn = GetConn.get();
                DataSet ds = new DataSet();
                SqlConnection conn = getConn.Conn();
                SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
                ad.Fill(ds);
                return ds;
            }
    //实现接口
    #region NewsSortDao 成员        public DataSet queryNewsSortInfoId(string NewsSortID)
            {
                string sql =string.Format( "select * from NewsSort where ClassID={0}",NewsSortID);
                return this.FillDS(sql);
            }
            #endregion
    页面的。CS
    public partial class admin_Manage : System.Web.UI.Page
    {
        private News news = new News();
        public int curPage;//当前页
        public int curCount;//一共页
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!this.IsPostBack){
                this.start();
                this.bingDropDownList1();
            }    
        }
        //开始加载dataList1
        void start() {
            if (Request.QueryString.Count != 0)
            {
                String NewsSortID="";
                 String NewsSortName="";
                 try
                 {
                     NewsSortID = Request.QueryString["NewsSortID"].ToString();
                     NewsSortName = Request.QueryString["NewsSortName"].ToString();       
                 }
                 catch {
                 }
                 if (NewsSortID == "" || NewsSortName=="") {
                     NewsSortID = "1";
                     NewsSortName = "最新简讯";
                 }
                 curCount = news.countNews(NewsSortID);
                 curPage=Util.getCurPage(curPage.ToString(), curCount);
                 HttpCookie ck = new HttpCookie("count", this.curCount.ToString());
                 HttpCookie pa = new HttpCookie("curPage", this.curPage.ToString());
                 Response.Cookies.Add(ck);
                 Response.Cookies.Add(pa);
                 DataSet ds = news.queryInitialize(NewsSortID, NewsSortName, curPage);
                if (ds.Tables[0].Rows.Count != 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["tile"]==DBNull.Value) {
                            ds.Tables[0].Rows[i]["tile"] = ds.Tables[0].Rows[i]["content"].ToString().Substring(1, 10);
                        }
                    }
                    this.DataList1.DataSource = ds;
                    this.DataList1.DataBind();
                }
            }   
        }    //绑定下拉框
        void bingDropDownList1() {
            if (Request.QueryString.Count != 0)
            {
                String NewsSortID = Request.QueryString["NewsSortID"].ToString();
                NewsSort newSort = new NewsSort();
                DataSet ds= newSort.queryNewsSortInfoId(NewsSortID);
                if (ds.Tables[0].Rows.Count == 1 || ds.Tables[0].Rows.Count == 0)
                {
                    this.Button3.Visible = false;
                    this.TextBox1.Visible = false;
                    this.DropDownList1.Visible = false;
                }
               
                    this.DropDownList1.DataSource = ds;
                    this.DropDownList1.DataBind();
                        }
        }    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "one")
            {
                //第一页
                this.curPage = 1;
                this.start();
            }
            else if (e.CommandName == "next")
            {
                //下一页
                this.curPage = Convert.ToInt32(Request.Cookies["curPage"].Value.ToString()) + 1;
                this.start();
            }
            else if (e.CommandName == "lastpage")
            {
                //上一页
                this.curPage = Convert.ToInt32(Request.Cookies["curPage"].Value.ToString()) - 1;
                this.start();
            }
            else if (e.CommandName == "last")
            {
                //最后一页
                this.curPage = Convert.ToInt32(Request.Cookies["count"].Value.ToString());
                this.start();
            }
            else if (e.CommandName == "go")
            {
                //到第几页
                try
                {
                    this.curPage = Convert.ToInt32(Request.QueryString["curPage"].ToString());
                }
                catch {
                    this.curPage = 1;
                }
                this.start();
            }
            else if (e.CommandName == "de")
            {
                string de = "";
                for (int i = 0; i < this.DataList1.Items.Count; i++)
                {
                    HtmlInputCheckBox chdel = this.DataList1.Items[i].FindControl("ckdel") as HtmlInputCheckBox;
                    if (chdel != null)
                    {
                        if (chdel.Checked)
                        {
                            de += chdel.Value + ",";
                        }
                    }            }
                de = de.Substring(0, de.Length - 1);
                if (news.deNews(de))
                {
                    Response.Write("<script>alert('删除成功!');</script>");
                }
                else {
                    Response.Write("<script>alert('删除失败!');</script>");
                }
                this.start();        }
        }    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
        {
            if (this.DropDownList1.SelectedItem.Text == null || this.DropDownList1.SelectedItem.Text == "")
            {        }
            else
            {
                string NewsSortName = this.DropDownList1.SelectedItem.Text;
                curCount = news.countNews(NewsSortName);
                curPage = Util.getCurPage(curPage.ToString(), curCount);
                HttpCookie ck = new HttpCookie("count", this.curCount.ToString());
                HttpCookie pa = new HttpCookie("curPage", this.curPage.ToString());
                Response.Cookies.Add(ck);
                Response.Cookies.Add(pa);
                DataSet ds = news.queryInitialize(NewsSortName, curPage);
                if (ds.Tables[0].Rows.Count != 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["tile"] == DBNull.Value)
                        {
                            ds.Tables[0].Rows[i]["tile"] = ds.Tables[0].Rows[i]["content"].ToString().Substring(1, 10);
                        }
                    }
                    this.DataList1.DataSource = ds;
                    this.DataList1.DataBind();
                }
       
            }
        }
        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.DropDownList1.SelectedItem.Text == null || this.DropDownList1.SelectedItem.Text == "")
            {        }
            else
            {
                string NewsSortName = this.DropDownList1.SelectedItem.Text;
                curCount = news.countNews(NewsSortName);
                curPage = Util.getCurPage(curPage.ToString(), curCount);
                HttpCookie ck = new HttpCookie("count", this.curCount.ToString());
                HttpCookie pa = new HttpCookie("curPage", this.curPage.ToString());
                Response.Cookies.Add(ck);
                Response.Cookies.Add(pa);
                DataSet ds = news.queryInitialize(NewsSortName, curPage);
                if (ds.Tables[0].Rows.Count != 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["tile"] == DBNull.Value)
                        {
                            ds.Tables[0].Rows[i]["tile"] = ds.Tables[0].Rows[i]["content"].ToString().Substring(1, 10);
                        }
                    }
                    this.DataList1.DataSource = ds;
                    this.DataList1.DataBind();
                }        }
        }
    }//页面<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1" DataTextField="Name" DataValueField="ClassID"> 
                    </asp:DropDownList> 
      

  8.   

    断点跟踪:
    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
        {
            if (this.DropDownList1.SelectedItem.Text == null || this.DropDownList1.SelectedItem.Text == "")
            {  这里this.DropDownList1.SelectedItem.Text的值
      

  9.   

    你先不要房在IsPostBack中测试,你直接测试,看他能不能运行,要不也可以放在RowDataBound事件中测试下
      

  10.   

    断点跟踪不了`RowDataBound这个软个我还没听说过`!
      

  11.   

    不房到IsPostBack
    他每次都什么执行加载事件其它也不会执行