ASPXGridView外觀顯示

來源:互聯網
上載者:User
  一。ASPXGridView外觀顯示
屬性:
Caption---- 列的標題(
KeyFieldName---- 資料庫欄位
SEOFriendly 是否啟用搜尋引擎最佳化
Summary 指定分頁匯總資訊的格式

Setting節點的ShowFilterRow= True設定快速尋找功能

SettingsBehavior.AllowFocusedRow=true  高亮選中的行,即選中行變色
SettingsBehavior.AllDragDrop= false禁止拖動標題列頭
SettingsBehavior.AllowSort實現列頭點擊後是否可以排序
SettingsPager.ShowEmptyDataRows= True;當資料行為空白時,顯示空行
SettingsPager.PageSize 每頁顯示的記錄總數
AllButton.Text “全部資料顯示”按鈕的文本
AllButton.Visible  是否顯示“全部資料顯示”按鈕
FirstPageBuotton/LastPageButton/NextPageButton/PrevPageButton/  對應首頁、末頁、下頁、上頁,設定同上。
NumericButtonCount 最小值為1,控制頁碼顯示個數
protectedvoid ASPxGridView1_PageIndexChanged(object  sender, EventArgs e)
    {
        databind();//只需重新綁定資料即可實現上下翻頁
    }
建立的列預設是GridViewDataTextColumn類型,選擇工具列的Change To變更列的類型,可以改變新增或修改時的編輯方式。
設定日期類型顯示格式,在“行為”PropertiesDateEdit--DisplayFormatString--例如:{0 :yyyy年MM月}

當選擇了show Group Panel時,FocusedRowChanged事件,重綁定資料,使用時先選中行,再查看
protectedvoid ASPxGridView1_FocusedRowChanged(object  sender, EventArgs e)
    {
        getdata();
    }

禁止某一列進行編輯,該列的行為-EditFormSettings-Visible= False

代碼中隱藏編輯列的增加,刪除,更新按鈕
(ASPxGridView1.Columns[編輯列] as GridViewCommandColumn).NewButton .Visible=true ;
(ASPxGridView1.Columns[編輯列] as GridViewCommandColumn).DeleteButton.Visible =true ;
(ASPxGridView1.Columns[8] as GridViewCommandColumn).UpdateButton .Visible=true ;
二。ASPXGridView綁定資料
ASPxGridView1.KeyFieldName ="ID";//指定主鍵。直接更新資料和子表綁定 需要用到

ASPxGridView1.DataSource  = dt.defaultView;//指定Grid的資料
ASPxGridView1.DataBind();  //執行綁定
注意,如果查詢結果欄位有別名,編輯該欄位時,UnboundType應設為Object
三。ASPXGridView尋找
過濾資料,尋找資料
方式一、展開欄位標題旁邊的過濾清單過濾資料(類似Excel的過濾方式)grid.Settings.ShowHeaderFilterButton=true;過濾清單列出了該列出現的所有資料。還可以自訂過濾清單的內容,用法參閱:http://demos.devexpress.com/ASPxGridViewDemos/Filtering/HeaderFilter.aspx

方式二、在列頭顯示欄位過濾條件輸入框 grid.Settings.ShowFilterRow  =true; 顯示條件判斷方式下拉式清單grid.Settings.ShowFilterRowMenu =true ;



四刪除資料
  protectedvoid ASPxGridView1_RowDeleting(object  sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
    {
      e.Cancel =true;//否則,只有重新整理頁面才能看到刪除後的結果
        int id =Convert.ToInt32( e.Keys[0]);//擷取ID
      upd.DelDownFileList(id);//從資料庫刪除記錄
    UpLoadFileListBind();//資料表綁定

    }
ASPxGridView內建的刪除提示,設兩個屬性即可:
SettingsBehavior.  ==> ConfirmDelete= True
SettingsText ==> ConfirmDelete= 要提示的字串
五.更新
取值 用e.NewValues[索引]
並且記得更新資料後 ASPxGridView1.CancelEdit();//結束編輯狀態
        e.Cancel =true ;
        bind();
例子: //更新
    protectedvoid ASPxGridView1_RowUpdating(object  sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        Bill.Message m =new  Bill.Message();

        //取值 用e.NewValues[索引]
        string id = Convert.ToString(e.Keys[0 ]);
        string event_date = e.NewValues[1 ].ToString();
        string event_title = e.NewValues[2 ].ToString();
        string event_description = e.NewValues[3 ].ToString();
        string tag = e.NewValues[4 ].ToString();
        m.Message_update(id, event_date, event_title, event_description, tag);
       
        ASPxGridView1.CancelEdit();//結束編輯狀態
        e.Cancel =true ;
        bind();
    }
六排序
在BeforeColumnSortingGrouping事件中重新綁定一下資料
七.分頁
PageIndexChanged事件裡重新綁定一下資料


1 .動態添加非資料繫結列,例子:動態添加行號列
if (! IsPostBack)
        {
            //動態添加行號非綁定資料
            GridViewDataTextColumn dl =new  GridViewDataTextColumn();
            dl.Caption ="行號" ;
            dl.FieldName ="hh";//該資料行繫結的欄位hh
            dl.UnboundType = DevExpress.Data.UnboundColumnType.String;//非資料繫結類型為字元型
            dl.PropertiesTextEdit.DisplayFormatString ="c";//顯示字元的格式
            dl.PropertiesTextEdit.FocusedStyle.ForeColor =  System.Drawing.Color.Red;
            dl.VisibleIndex =0;//設定行號列的索引位置
            ASPxGridView1.Columns.Insert(0, dl);//把行號列插入0之前
           
           
            getdata();
            ASPxGridView1.Caption ="IP為"+GetClientIP()+"的使用者,正在查看網銀終端更新內容" ;
   
        }

在CustomUnboundColumnData事件中
protectedvoid ASPxGridView1_CustomUnboundColumnData(object  sender, ASPxGridViewColumnDataEventArgs e)
    {
        if (e.Column.FieldName =="hh"&&  e.IsGetData)
            e.Value = (e.ListSourceRowIndex +1 ).ToString();
    }

2 .ASPxComboBox列的相關操作
簡單的方法是
1 .FiledName寫主表與此欄位有關聯外鍵欄位:例如uid
2 .在PropertiesCombobox下面找這幾個屬性:
然後在客戶姓名的這一列的DataSourceId,給它綁定上我們字表的ObjectDataSource
在TextField設定欄位名稱,例如:name
在ValueField設定名稱應該就是字表的主鍵(也就是主表引用字表的外鍵),例如:uid
這樣就可以輕鬆做到,不用寫代碼,綁定多張表

手寫代碼的方法來綁定ASPxComboBox
在aspx中將該列的-行為-PropertiesComboBox- ValuesType設為System.String避免ComboBox出現無法選中的現象

using  DevExpress.Web.ASPxGridView;
using  DevExpress.Web.ASPxEditors;
//在頁面載入時,給combox列賦值,這裡的workgroupID是在ASPxGridview中的Combox資料行繫結的欄位
        (ASPxGridView1.Columns["

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.