我有一个telerik雷达栅格,如下面所示
| Username | Password |
-------------------------
| A_user | ***** |
| A_user2 | ***** |
| A_user3 | ***** |
当我点击其中一行时,它会显示点击行的密码,如下所示:
| Username | Password |
-------------------------
| A_user | ***** |
| A_user2 | A password |
| A_user3 | ***** |
这很好。我这样做是因为密码的解密是一个相当复杂和漫长的过程,所以一次解密一个密码不那么耗时,尤其是当用户不需要所有密码时。
当我显示密码时,我希望能够在网格中选择密码来复制它。不幸的是,radgrid将再次触发"RowClick"项命令,并且该行将被取消选择。因此,我无法复制密码。
我的问题是:在某些情况下,有没有办法取消radgrid的itemcommand我希望能够在密码已经解密时禁用itemcommand事件。
提前感谢!
编辑:我想我还应该提到的是,当网格加载时,我使用radajaxloadingpanel在网格上显示动画。即使itemcommand方法什么都不做,也会显示ajaxloadingpanel,并且我试图高亮显示的文本会被取消选择。
更多编辑:
这是我的雷达网格代码
<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=".Imagesok.gif" UpdateImageUrl=".Imagesok.gif" CancelImageUrl=".Imagescancel.gif" />
<%--Delete--%>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Delete"
ImageUrl=".Imagesdelete.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
}
}