码迷,mamicode.com
首页 > Web开发 > 详细

Telerik for AJAX RadGrid控件

时间:2016-04-22 16:08:03      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:

作为一名.net小白,今天分享一下telerik知识的学习。熟悉ASP.NET Web Form的都知道Grid View或者是List View等表格控件,所以今天和大家分享一下telerik RadGrid的简单应用。

 

和一般表格控件一样,RadGrid有Datasource和一些点击事件,一些属性(例如分页,编辑,删除)

<telerik:RadGrid ID="RadGrid" runat="server" AllowPaging="true" AllowSorting="true" AllowCustomPaging="true"
                        OnNeedDataSource="RadGrid_NeedDataSource" LoadingPanelID="RadAjaxLoadingPanel" AutoGenerateColumns="false"
                        AllowAutomaticUpdates="True" AllowAutomaticDeletes="true" AllowMultiRowSelection="True">
                        <MasterTableView DataKeyNames="Account, Staff_ID, Manager_ID" NoMasterRecordsText="暂无数据">
                            <Columns>

                                <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn">
                                </telerik:GridClientSelectColumn>

                                <telerik:GridBoundColumn UniqueName="Account" HeaderText="账号" DataField="Account">
                                </telerik:GridBoundColumn>

                                <telerik:GridBoundColumn UniqueName="Number" HeaderText="编号" DataField="Number">
                                </telerik:GridBoundColumn>

                                <telerik:GridBoundColumn UniqueName="Name" HeaderText="姓名" DataField="Name">
                                </telerik:GridBoundColumn>

                                <telerik:GridBoundColumn UniqueName="Staff_Name" HeaderText="员工" DataField="Staff_Name">
                                </telerik:GridBoundColumn>

                                <telerik:GridBoundColumn UniqueName="Manager_Name" HeaderText="经理" DataField="Manager_Name">
                                </telerik:GridBoundColumn>

                                <telerik:GridBoundColumn UniqueName="Department_Name" HeaderText="部门" DataField="Department_Name">
                                </telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                        <PagerStyle FirstPageToolTip="首页" PrevPageToolTip="上一页" NextPageToolTip="下一页" LastPageToolTip="尾页" PrevPagesToolTip="前10页" NextPagesToolTip="后10页"
                            PageSizeLabelText="每页显示数" PagerTextFormat="{4}共 <strong>{5}</strong> 条数据" />
                        <ExportSettings Excel-Format="Biff" IgnorePaging="true" ExportOnlyData="true" OpenInNewWindow="true"></ExportSettings>

                        <ClientSettings EnableRowHoverStyle="false">
                            <Selecting AllowRowSelect="true" UseClientSelectColumnOnly="true"></Selecting>
                        </ClientSettings>

                    </telerik:RadGrid>

DataKeyName:绑定字段值,可以绑定多个字段

OnNeedDataSource:数据源,用于绑定数据

DataField:对应数据库字段也就是映射表里面的字段

PageStyle:设置可以配合linq来进行分页

GridClientSelectColumn:设置表格单选

 

RadGrid后台如何获取字段的值(类似于GridView)

代码如下:

 1     private void GetSelectItems()
 2     {
 3         foreach (GridDataItem item in RadGrid.SelectedItems)
 4         {
 5             CustomerBatchChangeRecordVO record = new CustomerBatchChangeRecordVO();
 6 
 7             var editableItem = ((GridEditableItem)item);
 8             var staffID = (int)editableItem.GetDataKeyValue("Staff_ID");
 9             var managerID = (int)editableItem.GetDataKeyValue("Manager_ID");
10 
11             record.Old_Staff_ID = staffID;
12             record.Old_Manager_ID = managerID;
13             record.Account = item["Account"].Text;
14             record.Account_Name = item["Name"].Text;
15             record.Customer_Number = item["Number"].Text;
16             record.Old_Manager_Name = item["Manager_Name"].Text;
17             record.Old_Staff_Name = item["Staff_Name"].Text;
18             record.Department_Name = item["Department_Name"].Text;
19             recordList.Add(record);
20         }
21         Session[Config.Seesion_CustomerBatchChangeRecord] = recordList;
22 
23     }

获取多行选中的值:

 1 // 通过DataKeyValues获取
 2 foreach (GridDataItem item in rg.SelectedItems)
 3 {
 4     var value = item.GetDataKeyValue("Id");
 5     var value = rg.MasterTableView.DataKeyValues[item.ItemIndex]["Id"];
 6 }
 7  
 8 foreach (string item in rg.SelectedIndexes)
 9 {
10     var value = rg.MasterTableView.DataKeyValues[int.Parse(item)]["Id"];
11     var value = rg.Items[int.Parse(item)].GetDataKeyValue("Id");
12 }
13  
14 // 通过ExtractValues获取
15 foreach (GridDataItem item in rg.SelectedItems)
16 {
17     var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
18     item.ExtractValues(dict);
19     var value = dict["Id"];
20 }
21  
22 foreach (string item in rg.SelectedIndexes)
23 {
24     var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
25     rg.Items[int.Parse(item)].ExtractValues(dict);
26     var value = dict["Id"];
27 }
28  
29 // 通过TableCell获取
30 foreach (GridDataItem item in rg.SelectedItems)
31 {
32     var value = item["idCol"].Text; // GridBoundColumn
33     var value = (item.FindControl("idText") as Literal).Text; // GridTemplateColumn
34 }
35  
36 foreach (string item in rg.SelectedIndexes)
37 {
38     var value = rg.Items[int.Parse(item)]["idCol"].Text; // GridBoundColumn
39     var value = (rg.Items[int.Parse(item)].FindControl("idText") as Literal).Text; // GridTemplateColumn
40 
41 }

 

初次涉及telerik RadGrid,请大家指教 O(∩_∩)O

Telerik for AJAX RadGrid控件

标签:

原文地址:http://www.cnblogs.com/jacksundatashare/p/telerik.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!