Telerik的文本选择

我有一个Telerik的radgrid控件,如下面所示

| Username | Password | ------------------------- | A_user | ***** | | A_user2 | ***** | | A_user3 | ***** |

当我点击行之一,它会显示点击的行的密码,就像这样:

| Username | Password | ------------------------- | A_user | ***** | | A_user2 | A password | | A_user3 | ***** |

这工作正常。 我继续这种方式,因为密码的解密是一个相当复杂的和长期的过程,在一个时间,以便解密一个口令是耗时更少,特别是当用户不需要所有的密码。

当我显示了密码,我希望能够在网格中选择密码来复制它。 不幸的是,radgrid控件将触发“RowClick”itemcommand一次以上,并且该行被取消选择。 因此,我不能复制的密码。

我的问题是: 有没有办法取消在某些情况下一个radgrid控件的itemcommand我希望能够禁用ItemCommand事件时,口令已经被解密

提前致谢!

编辑:我想我也应该提的是,我使用的是radajaxloadingpanel显示在网格的动画时,它的加载。 即使在itemcommand方法不执行任何操作,显示ajaxloadingpanel,我尽量突出文本被取消选择。

多个编辑:

这里是我的radgrid控件的代码

<telerik:RadGrid id="radGridAccounts" runat="server" Width="99%" PageSize="20" AllowPaging="true" AllowSorting="true" AllowFilteringByColumn="True" ShowStatusBar="true" EnableLinqExpressions="False" GridLines="None" AllowMultiRowSelection="false"> <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true" AllowKeyboardNavigation="false"> <Selecting AllowRowSelect="True" /> <KeyboardNavigationSettings EnableKeyboardShortcuts="false" /> </ClientSettings> <PagerStyle Mode="NextPrevAndNumeric" PagerTextFormat=""/> <MasterTableView AutoGenerateColumns="False" EditMode="InPlace" CommandItemDisplay="Top" InsertItemDisplay="Top" AllowFilteringByColumn="True" NoMasterRecordsText="Aucun compte" InsertItemPageIndexAction="ShowItemOnCurrentPage" DataKeyNames="USERN" > <Columns> <%--Username--%> <telerik:GridBoundColumn UniqueName="USERN" DataField="USERN" HeaderText="Username" AllowFiltering="true" ColumnEditorID="radUsernameEditor"/> <%--Password--%> <telerik:GridBoundColumn UniqueName="PASWR" DataField="PASWR" HeaderText="Password" AllowFiltering="false" ColumnEditorID="radPasswordEditor" /> <%--Edit--%> <telerik:GridEditCommandColumn ButtonType="ImageButton" InsertImageUrl=".\Images\ok.gif" UpdateImageUrl=".\Images\ok.gif" CancelImageUrl=".\Images\cancel.gif" /> <%--Delete--%> <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Delete" ImageUrl=".\Images\delete.gif" /> </Columns> <CommandItemSettings AddNewRecordText="" RefreshText="" /> </MasterTableView> </telerik:RadGrid>

而我的ItemCommand代码:

Protected Sub radGridAccounts_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles radGridAccounts.ItemCommand Try If (e.CommandName = "RowClick" AndAlso TypeOf e.Item Is GridDataItem) Then e.Item.Selected = True For Each item As GridDataItem In radGridAccounts.Items If Not item.IsInEditMode Then If item.Selected Then 'Decrypt the password method Else item.Cells(4).Text = "*****" End If End If Next End If Catch ex As Exception DisplayMessage("Error : " & ex.Message, MessageType.Err) End Try End Sub

--------------解决方案-------------

切换到上radgrid控件OnSelectedIndexChanged功能和当前选中的行存储在客户方的变量,并处理rowSelected客户端事件,并取消或者允许回发的情况发生,还可以添加在你想要使用的ClientDataKeyName。

<telerik:RadGrid id="radGridAccounts" runat="server" Width="99%" PageSize="20" AllowPaging="true" AllowSorting="true" OnSelectedIndexChanged="RadGridAccounts_SelectedIndexChanged"
AllowFilteringByColumn="True" ShowStatusBar="true" EnableLinqExpressions="False" GridLines="None"
AllowMultiRowSelection="false">

<ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true" EnableAllowKeyboardNavigation="false">
<Selecting AllowRowSelect="True" />
<KeyboardNavigationSettings EnableKeyboardShortcuts="false" />
<ClientEvents OnRowSelected="rowSelected" />
</ClientSettings>
<PagerStyle Mode="NextPrevAndNumeric" PagerTextFormat=""/>

<MasterTableView AutoGenerateColumns="False" EditMode="InPlace" CommandItemDisplay="Top"
InsertItemDisplay="Top" AllowFilteringByColumn="True" NoMasterRecordsText="Aucun compte"
InsertItemPageIndexAction="ShowItemOnCurrentPage" DataKeyNames="USERN" ClientDataKeyNames="USERN" >

<Columns>
...
</Columns>
<CommandItemSettings AddNewRecordText="" RefreshText="" />

</MasterTableView>
</telerik:RadGrid>

<script type="text/javascript">
var selectedUserName;//global js var
function rowSelected(senders, args)
{
//get the ClientDataKeyName
var rowUserName= args.getDataKeyValue("USERN");
if(selectedUserName == rowUserName){
args.set_cancel(true);//cancel the postback
}
}
</script>

然后在服务器端:

protected void RadGridAccounts_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadGridAccounts.SelectedItems == null || RadGridAccounts.SelectedItems.Count == 0)
return;

var dataItem = RadGridAccounts.SelectedItems[0] as GridDataItem;
if (dataItem != null)
{
//do the password look up
}
}

分类:asp.net 时间:2015-03-15 人气:0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 1.099 (s). 10 q(s)