asp.net – 如何从Telerik RadGrid获取“KeyValue”?
发布时间:2020-12-15 19:40:47 所属栏目:asp.Net 来源:网络整理
导读:telerik:RadGrid ID="radGrid" runat="server" AllowPaging="true" AllowCustomPaging="True" GridLines="None" PageSize="20" AllowMultiRowSelection="true" ClientSettings-Selecting-AllowRowSelect="true" AutoGenerateColumns="false" onneeddatasourc
<telerik:RadGrid ID="radGrid" runat="server" AllowPaging="true" AllowCustomPaging="True" GridLines="None" PageSize="20" AllowMultiRowSelection="true" ClientSettings-Selecting-AllowRowSelect="true" AutoGenerateColumns="false" onneeddatasource="radGrid_NeedDataSource" OnItemCreated="radGrid_ItemCreated" OnItemDataBound="radGrid_ItemDataBound" OnItemCommand="radGrid_ItemCommand" DataKeyNames="ClientID"> <mastertableview datakeynames="ID" gridlines="None" width="100%"> <PagerTemplate> and so on ... </telerik:RadGrid> 情况: – 以上是我正在使用的Telerik RagGrid控件的标记.我试图访问GridColumn的KeyValue,通常的方式, Int32 key = Convert.ToInt32((e.Item as GridDataItem).GetDataKeyValue("ID")); 这不行.有替补吗? 解决方法
请尝试以下代码片段.
protected void RadGrid1_ItemDataBound(object sender,GridItemEventArgs e) { if (e.Item is GridDataItem) { // NORMAL MODE GridDataItem item = e.Item as GridDataItem; string strId = item.GetDataKeyValue("ID").ToString(); } if (e.Item is GridEditableItem && e.Item.IsInEditMode) { if (e.Item is GridEditFormInsertItem) { // INSERT MODE GridEditableItem editedItem = e.Item as GridEditableItem; } else { // EDIT MODE GridEditableItem editedItem = e.Item as GridEditableItem; string strId = editedItem.GetDataKeyValue("ID").ToString(); } } } protected void RadGrid1_ItemCommand(object sender,GridCommandEventArgs e) { if (e.CommandName == "YourCommandName") { GridDataItem item = e.Item as GridDataItem; string strId = item.GetDataKeyValue("ID").ToString(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET表单认证在iPad上显示登录页面
- asp.net – FormView ConvertEmptyStringToNull和绑定
- 如何解决HP QC(Quality Center)在Windows 7下不能工作的问题
- asp.net-mvc – ASP.NET MVC5 EF6与ApplicationUser的关系
- ASP.Net是适用于高负载网站的技术吗?
- ASP.net处理XML数据实例浅析
- asp.net webservice处理gzip压缩请求
- asp.net-mvc – Razor视图与部分视图
- ASP.net用户数据在访问对象的用户之间进行交叉
- ASP.NET 2.5前缀ctl00和ASP.NET 4不是前缀ctl00