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

GridView控件的使用-創(chuàng)新互聯(lián)

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

創(chuàng)新互聯(lián)建站專注于慶元企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),商城建設(shè)。慶元網(wǎng)站建設(shè)公司,為慶元等地區(qū)提供建站服務(wù)。全流程按需策劃設(shè)計,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)

 private void showData(String sql)
        {
            try
            {
                //自動生成表頭
                this.gridSend.AutoGenerateColumns = true;
                //這個屬性是當(dāng)你點擊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)文本框,顯示報表標(biāo)題文字
            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);

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

分享文章:GridView控件的使用-創(chuàng)新互聯(lián)
網(wǎng)頁網(wǎng)址:http://www.chinadenli.net/article48/dheeep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計云服務(wù)器網(wǎng)站建設(shè)自適應(yīng)網(wǎng)站營銷型網(wǎng)站建設(shè)Google

廣告

聲明:本網(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)

外貿(mào)網(wǎng)站建設(shè)