我是telerik组件的新手。我有一个包含Radgrid的页面,我想从后面的代码中禁用radgrid中的编辑。我已经禁用了我认为会影响编辑的所有内容,但它仍然在行 - 双击上进行编辑。我怎么能禁用它?
<telerik:RadGrid ID="RadGrid_ElateTarkeKar" runat="server" CssClass="RadGrid" GridLines="None"
AllowPaging="True" PageSize="20" AllowSorting="True" AutoGenerateColumns="False"
ShowStatusBar="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" ClientSettings-Selecting-AllowRowSelect="true"
AllowAutomaticUpdates="True" DataSourceID="SqldtsElateTarkeKar" CellSpacing="0" AllowFilteringByColumn="True"
OnInsertCommand="RadGrid_ElateTarkeKar_InsertCommand" OnItemCommand="RadGrid_ElateTarkeKar_ItemCommand"
OnItemDeleted="RadGrid_ElateTarkeKar_ItemDeleted" OnItemInserted="RadGrid_ElateTarkeKar_ItemInserted"
OnItemUpdated="RadGrid_ElateTarkeKar_ItemUpdated" OnUpdateCommand="RadGrid_ElateTarkeKar_UpdateCommand" Width="100%" Height="250px" Skin="Hay">
<ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
<Excel Format="ExcelML"></Excel>
<Excel AutoFitImages="true" />
<Pdf FontType="Embed" AllowPrinting="true" />
<Pdf DefaultFontFamily="Arial Unicode MS" />
</ExportSettings>
<MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="ElateTarkeKar_ID" EditMode="PopUp" Dir="RTL" AllowFilteringByColumn="true" NoDetailRecordsText="هیچ رکوردی وجود ندارد !" NoMasterRecordsText="هیچ رکوردی وجود ندارد !" DataSourceID="SqldtsElateTarkeKar">
<CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="ایجاد رکورد جدید" RefreshText="بروزرسانی" ShowExportToExcelButton="true" ShowExportToWordButton="true" ShowExportToPdfButton="false"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" FilterControlWidth="20%"></RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column" FilterControlWidth="20%"></ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn UniqueName="ElateTarkeKar_ID" HeaderText="کد علت ترک کار" DataField="ElateTarkeKar_ID" FilterControlAltText="Filter ElateTarkeKar_ID column" ReadOnly="True" SortExpression="ElateTarkeKar_ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="ElateTarkeKar_Desc" HeaderText="علت ترک کار" DataField="ElateTarkeKar_Desc" FilterControlAltText="Filter ElateTarkeKar_Desc column" SortExpression="ElateTarkeKar_Desc">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" Text="حذف" UniqueName="columnDelete" ConfirmText="آیا می خواهید رکورد مورد نظر را حذف کنید ؟" ConfirmDialogType="RadWindow" ImageUrl="../../assets/img/icon/del-layer.png" ConfirmDialogHeight="180" ConfirmDialogWidth="380" FooterStyle-Width="60px" HeaderStyle-Width="60px" ItemStyle-Width="60px">
</telerik:GridButtonColumn>
<telerik:GridButtonColumn CommandName="Edit" AndCurrentFilterFunction="Contains" ButtonType="ImageButton" ImageUrl="../../assets/img/icon/edit.png" AutoPostBackOnFilter="True" CurrentFilterFunction="Contains" Text="ویرایش" FooterStyle-Width="60px" HeaderStyle-Width="60px" ItemStyle-Width="60px" UniqueName="columnEdit">
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings InsertCaption="ایجاد علت ترک کار جدید" CaptionFormatString="ویرایش علت ترک کار با کد : {0}"
CaptionDataField="ElateTarkeKar_ID" EditFormType="Template" PopUpSettings-Modal="true" FormTableStyle-HorizontalAlign="Center" FormCaptionStyle-HorizontalAlign="Center" PopUpSettings-CloseButtonToolTip="بستن" UserControlName="popupform" PopUpSettings-Width="500">
<EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
<FormTableStyle HorizontalAlign="Center"></FormTableStyle>
<FormCaptionStyle HorizontalAlign="Center"></FormCaptionStyle>
<FormTemplate >
<br/>
<div class="portlet-body form form-horizontal">
<div id="Div1" class="control-group" runat="server" visible="false">
<label class="control-label">
کد علت ترک کار :
</label>
<div class="controls">
<asp:TextBox ID="txtElateTarkeKar_ID" Text='<%# Bind( "ElateTarkeKar_ID") %>' runat="server">
</asp:TextBox>
</div>
</div>
<div class="row-fluid">
<div class="span11">
<div class="control-group">
<label class="control-label">علت ترک کار :</label>
<div class="controls">
<asp:TextBox ID="txtElateTarkeKar_Desc" Text='<%# Bind("ElateTarkeKar_Desc")%>' CssClass="span10 tooltips pulsate-regular" ClientIDMode="Static" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" Font-Size="Large" ControlToValidate="txtElateTarkeKar_Desc"></asp:RequiredFieldValidator>
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<div class="control-group">
<label class="control-label">
</label>
<div class="controls">
</div>
</div>
</div>
</div>
<div class="ipopup-actions">
<asp:LinkButton CssClass="btn green" runat="server" ID="Button3" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
<i class="icon-ok"></i>
<%# (Container is GridEditFormInsertItem) ? "درج" : "ویرایش" %>
</asp:LinkButton>
<asp:LinkButton CssClass="btn grey" runat="server" ID="Button4" CausesValidation="False" CommandName="Cancel">
<i class="icon-remove"></i> انصراف
</asp:LinkButton>
</div>
</div>
</FormTemplate>
<PopUpSettings Modal="True" Width="500px" CloseButtonToolTip="بستن"></PopUpSettings>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox" />
</MasterTableView>
<ClientSettings ClientEvents-OnKeyPress="keyPress">
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowDblClick="RowDblClick" />
<ClientEvents OnPopUpShowing="PopUpShowing" />
</ClientSettings>
<FilterItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<PagerStyle PageSizeControlType="RadComboBox" />
<FilterMenu EnableImageSprites="False">
</FilterMenu>
</telerik:RadGrid>
`
答案:
在某些情况下,可以通过行双击进行编辑,因此我使用下面的代码来禁用此功能,然后我隐藏了编辑按钮:
radGrid.MasterTableView.EditMode = GridEditMode.InPlace;
radGrid.ClientSettings.ClientEvents.OnRowDblClick = "";
radGrid.MasterTableView.GetColumn("columnEdit").Display = false;
答案 0 :(得分:1)
假设您需要以编程方式禁用编辑/删除,此代码段应该可以完成以下任务:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (yourCondition)
{
foreach( GridDataItem item in RadGrid1.MasterTableView.Items )
{
LinkButton btnDelete = (LinkButton)item.FindControl("columnDelete");
btnDelete.Enabled = false;
LinkButton btnEdit = (LinkButton)item.FindControl("columnEdit");
btnEdit.Enabled = false;
}
}
}