欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

GridView控件的使用

    GridView控件,用表格的形式將數(shù)據(jù)顯示出來。那么如何將將數(shù)據(jù)綁定到GridView中呢?目前值學習了兩種,一種是直接綁定數(shù)據(jù)源,另一種是動態(tài)顯示數(shù)據(jù)(主要使用對象有SqlCommand,SqlDataAdapter,DateSet)。這里主要說一下后一種方法:

創(chuàng)新互聯(lián)主營雨山網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都APP應(yīng)用開發(fā),雨山h5小程序設(shè)計搭建,雨山網(wǎng)站營銷推廣歡迎雨山等地區(qū)企業(yè)咨詢

    

 private void showData(String sql)
        {
            try
            {
                //自動生成表頭
                this.gridSend.AutoGenerateColumns = true;
                //這個屬性是當你點擊GridView中任意一個單元格時,默認選中該單元格所在行
                this.gridSend.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                //簡單的數(shù)據(jù)庫連接
                SqlConnection conn = new SqlConnection("server=.\\sqlexpress;database=dodoo2;uid=s1;pwd=s1");
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                SqlDataAdapter da = new SqlDataAdapter();
                cmd.Connection = conn;
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                da.SelectCommand = cmd;
                DataSet ds = new DataSet();
                da.Fill(ds, "lb_billflow");
                this.gridSend.DataSource = ds.Tables[0];
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message+sqlSel);
            }
        }

顯示出數(shù)據(jù)后,通過CellClick()事件,獲取選中行的數(shù)據(jù),例如獲取選中行中的id值:

int id = Convert.ToInt16(gridSend.CurrentRow.Cell["ID"].value);

因為在做報表,還需要將GridView打印成報表。這里我用的是GridReport工具,這里邊提供了豐富的功能。可以直接做出現(xiàn)成的報表,在頁面通過GridReport.start()顯示,也可以通過編碼將GridView中的值傳如報表中。還是介紹后一種方法:

private void ReportFetchRecord() {
            for (int row = 0; row < gridSend.RowCount;++row )
            {
                Report.DetailGrid.Recordset.Append();
                //for循環(huán)中ColumnCount-1!如果沒有-1,會拋出
                for (int col = 0; col < gridSend.ColumnCount-1; ++col)
                   Report.DetailGrid.Recordset.Fields[col + 1].AsString = gridSend.Rows[r                            ow].Cells[col].Value.ToString();
               Report.DetailGrid.Recordset.Post();
            }
        }
private void DefineReport() {
            Report.Clear();//清空報表 
            Report.Printer.PaperOrientation = GRPaperOrientation.grpoLandscape;

            //定義表頭
            IGRReportHeader Reportheader = Report.InsertReportHeader();
            Reportheader.Height = 1.38;
            //插入一個靜態(tài)文本框,顯示報表標題文字
            IGRStaticBox StaticBox = Reportheader.Controls.Add(GRControlType.grctStaticBox).AsStaticBox;
            StaticBox.Text = "發(fā)放物品清單";
            StaticBox.Font.Point = 15;
            StaticBox.Font.Bold = true;
            StaticBox.Top = 0.40;
            StaticBox.Width = 5.64;
            StaticBox.Height = 0.58;

            //根據(jù)Gridview的列信息定義明細網(wǎng)絡(luò)
            Report.InsertDetailGrid();
            Report.DetailGrid.ColumnTitle.Height = 0.58;
            Report.DetailGrid.ColumnContent.Height = 0.58;
            //將數(shù)據(jù)寫入報表中
            IGRRecordset RecordSet = Report.DetailGrid.Recordset;
            for (int i = 0; i < gridSend.ColumnCount;++i )
            {
                string ColumnName = gridSend.Columns[i].Name;
                RecordSet.AddField(ColumnName,GRFieldType.grftString);
                double ReportColumnWidth = Convert.ToDouble(gridSend.Columns[i].Width)/50;
                Report.DetailGrid.AddColumn(ColumnName,gridSend.Columns[i].HeaderText,ColumnName,ReportColumnWidth);
            }
            
        }      
 窗體的構(gòu)造函數(shù)中添加:
 Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecord);  
 報表的打印預(yù)覽功能:Report.PrintPreview(true);

本文題目:GridView控件的使用
本文地址:http://chinadenli.net/article40/pgjjho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)標簽優(yōu)化網(wǎng)站設(shè)計微信公眾號服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)