台灣最大程式設計社群網站
線上人數
625
 
會員總數:246038
討論主題:189624
歡迎您免費加入會員
討論區列表 >> C# >> 請教DataGrid分頁的問題....
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
請教DataGrid分頁的問題....
價值 : 0 QP  點閱數:1687 回應數:1
樓主

Jerry
初學者
4 5
12 0
發送站內信

請問 , 我在DataGrid的屬性產生器裡己設定分頁,但當程式執行後, 我點下一頁, 都沒有任何的反應, 麻煩那位高手可以指點一下..以下是我的程式碼. 謝謝!



namespace bincard
{
        /// <summary>
        /// Transfer_deliver 的摘要描述。
        /// </summary>
        public class Bincard_Query : System.Web.UI.Page
        {

                protected System.Web.UI.WebControls.TextBox tbEmpNo;
                protected System.Web.UI.WebControls.TextBox tbEmpName;
                protected System.Web.UI.WebControls.Button btnQuyEmpNo;
                protected System.Web.UI.WebControls.TextBox tbDiv;
                protected System.Web.UI.WebControls.TextBox tbOANo;
                protected System.Web.UI.WebControls.ImageButton imgbtnQuery;
                protected System.Web.UI.WebControls.ImageButton imgbtnClear;
                protected System.Web.UI.WebControls.DropDownList ddlBType;
                protected System.Web.UI.WebControls.TextBox tbCtrlNo;
                protected System.Web.UI.WebControls.Button tbQryCtrlNo;
                protected System.Web.UI.WebControls.DataGrid dgBinQry;

        
                private void Page_Load(object sender, System.EventArgs e)
                {
                        // 在這裡放置使用者程式碼以初始化網頁


                }

                #region Web Form 設計工具產生的程式碼
                override protected void OnInit(EventArgs e)
                {
                        //
                        // CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
                        //
                        InitializeComponent();
                        base.OnInit(e);
                }
                
                /// <summary>
                /// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
                /// 這個方法的內容。
                /// </summary>
                private void InitializeComponent()
                {    
                        this.btnQuyEmpNo.Click += new System.EventHandler(this.btnQuyEmpNo_Click);
                        this.imgbtnQuery.Click += new System.Web.UI.ImageClickEventHandler(this.imgbtnQuery_Click);
                        this.tbQryCtrlNo.Click += new System.EventHandler(this.btbQryCtrlNo_Click);
                        this.ddlBType.SelectedIndexChanged += new System.EventHandler(this.ddlBType_SelectedIndexChanged);
                        this.imgbtnClear.Click += new System.Web.UI.ImageClickEventHandler(this.imgbtnClear_Click);
                        this.dgBinQry.SelectedIndexChanged += new System.EventHandler(this.dgBinQry_SelectedIndexChanged);
                        this.Load += new System.EventHandler(this.Page_Load);

                }
                #endregion

                private void imgbtnQuery_Click(object sender, System.Web.UI.ImageClickEventArgs e)
                {
                        if ( tbEmpNo.Text.ToString() == "" && tbDiv.Text.ToString() =="" && tbOANo.Text.ToString() =="" && tbOANo.Text.ToString() =="")
                        {
                                // Popup視窗,顯示欄位不可為空白
                                Response.Write("<Script language=\"JavaScript\"> alert(\"欄位不可為空白!\"); </" + "Script>") ;
                                return;
                        }
                         string cnString = Application["ConnectString"].ToString();
                        string stringCmd = "SELECT c.div , c.name_c , a.bin_no as 'Bincard No', a.control_no as , a.model , a.qty , b.b_type , a.im_no, a.rcv_date, a.remark  FROM bin_d AS a, bin_m AS b, employee AS c WHERE a.flag<>'d' And a.bin_no=b.bin_no And b.emp_no=c.emp_no";
                        string bind ="";

                        if (tbEmpNo.Text.ToString() != "")
                        {
                                if ( bind == "")
                                {
                                        bind = " and c.emp_no like '"+ tbEmpNo.Text.ToString() +"'";
                                }
                                else
                                {
                                        bind = bind + " and c.emp_no like '"+ tbEmpNo.Text.ToString() +"'";
                                }
                        }

                        if (tbDiv.Text.ToString() !="")
                        {
                                if (bind =="")
                                {
                                        bind = " and c.div like '" + tbDiv.Text.ToString() + "%'";
                                }
                                else
                                {
                                        bind = bind + " and c.div like '" + tbDiv.Text.ToString() + "%'";
                                }
                        }

                        if (tbOANo.Text.ToString() !="")
                        {
                                if ( bind == "")
                                {
                                        bind = " and a.control_no = '" + tbOANo.Text.ToString() + "'";
                                }
                                else 
                                {
                                        bind = bind + " and a.control_no = '" + tbOANo.Text.ToString() + "'";
                                }
                        }
                        if (ddlBType.SelectedItem.ToString() != "")
                        {
                                if ( bind == "")
                                {
                                        bind = " and b.b_type = '" + ddlBType.SelectedItem.ToString() + "'";
                                }
                                else
                                {
                                        bind = bind + " and b.b_type = '" + ddlBType.SelectedItem.ToString() + "'";
                                }
                        }


                        string bindcmd = stringCmd + bind + " order by c.div, c.emp_no, a.control_no;";

                        OdbcConnection myConnection = new OdbcConnection(cnString);
                        myConnection.Open();
                        try
                        {
                                OdbcCommand cmd = new OdbcCommand(stringCmd);
                                OdbcDataAdapter da = new OdbcDataAdapter(bindcmd , myConnection);
                                DataSet ds = new DataSet();
                                
                        
                                dgBinQry.DataSource = ds.Tables;
                                dgBinQry.DataMember = "FAData";
                                da.Fill(ds, "FAData");

//                                if ( Page.IsPostBack ) 
//                                {
//                                        dgBinQry.DataBind();
//                                }
                                dgBinQry.DataBind();

                        }
                        catch (Exception exc) 
                        {
                                Response.Write( exc.ToString());
                        }
                        finally
                        {
                                myConnection.Close();
                                myConnection.Dispose();
                        }


                }

                private void ddlBType_SelectedIndexChanged(object sender, System.EventArgs e)
                {



                }

                private void btnQuyEmpNo_Click(object sender, System.EventArgs e)
                {
                        string cnString = Application["ConnectString"].ToString();
                        string qryEmpNo = "select emp_no from employee where name_c = '" + tbEmpName.Text.ToString() + "';";
                        OdbcConnection cn = new OdbcConnection(cnString);
                        OdbcCommand cmd = new OdbcCommand(qryEmpNo, cn);
                        OdbcDataReader dr;
                        cn.Open();
                        dr = cmd.ExecuteReader();
                        string strTemp;
                        while (dr.Read())
                        {
                                strTemp = dr.GetString(0);
                                tbEmpNo.Text = strTemp;
                        }
                        cn.Close();
                }

                private void btbQryCtrlNo_Click(object sender, System.EventArgs e)
                {
                        string cnString = Application["ConnectString"].ToString();
                        string qryCtrlNo = "select control_no from bin_d where remark = '" + tbCtrlNo.Text.ToString() + "';";
                        OdbcConnection cn = new OdbcConnection(cnString);
                        OdbcCommand cmd = new OdbcCommand(qryCtrlNo, cn);
                        OdbcDataReader dr;
                        cn.Open();
                        dr = cmd.ExecuteReader();
                        string strTemp;
                        while (dr.Read())
                        {
                                strTemp = dr.GetString(0);
                                tbOANo.Text = strTemp;
                        }
                        cn.Close();
                }

                private void imgbtnClear_Click(object sender, System.Web.UI.ImageClickEventArgs e)
                {
                        tbCtrlNo.Text = "";
                        tbDiv.Text = "";
                        tbEmpName.Text = "";
                        tbEmpNo.Text = "";
                        tbOANo.Text = "";

                        string cnString = Application["ConnectString"].ToString();
                        string stringCmd = "SELECT c.div , c.name_c , a.bin_no , a.control_no , a.model , a.qty , b.b_type , a.im_no , a.rcv_date , a.remark  FROM bin_d AS a, bin_m AS b, employee AS c WHERE a.control_no = '1';";

                        OdbcConnection myConnection = new OdbcConnection(cnString);
                        myConnection.Open();

                        OdbcCommand cmd = new OdbcCommand(stringCmd);
                        OdbcDataAdapter da = new OdbcDataAdapter(stringCmd , myConnection);
                        DataSet ds = new DataSet();
                                
                        dgBinQry.DataSource = ds.Tables;
                        dgBinQry.DataMember = "FAData";
                        da.Fill(ds, "FAData");
                        
                        dgBinQry.DataBind();
                }

                private void dgBinQry_SelectedIndexChanged(object sender, System.EventArgs e)
                {
                        
                }
        }
}

本篇文章發表於2004-01-30 16:07
1樓
回應

Eddie
檢舉此回應
要在DataGrid的PageIndexChanged事件處理函式裡加入下列程式
才可以換頁.

DataGrid1.CurrentPageIndex = e.NewPageIndex;
本篇文章回覆於2004-01-30 19:06
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.