我正在使用RadGrid显示一些数据并且我已将AllowFilteringByColumn设置为true,但是当我尝试过滤行时,会发生回发并且我的RadGrid内容消失(所有内容都消失,只剩下边框)。
<telerik:RadAjaxPanel ID="pnlShowGrid" runat="server" LoadingPanelID="RadAjaxLoadingPanel4">
<div class="row-fluid">
<telerik:RadGrid ID="RadGrid1" runat="server"
CssClass="RadGrid" Height="400px"
ClientSettings-Selecting-AllowRowSelect="true"
AllowPaging="True" PageSize="20" AllowSorting="True"
AutoGenerateColumns="False" AllowAutomaticUpdates="True"
ShowStatusBar="True" AllowAutomaticDeletes="True"
AllowFilteringByColumn="True"
Width="100%"
OnUpdateCommand="RadGrid1_UpdateCommand"
OnItemDeleted="rgrd_Edit_ItemDeleted"
OnItemCommand="RadGrid1_ItemCommand">
<ExportSettings ExportOnlyData="True">
<Pdf DefaultFontFamily="Arial Unicode MS" FontType="Embed" />
<Excel AutoFitImages="True" />
</ExportSettings>
<FilterMenu EnableImageSprites="true">
</FilterMenu>
<ExportSettings ExportOnlyData="true" OpenInNewWindow="true">
<Excel Format="ExcelML"></Excel>
<Excel AutoFitImages="true" />
<Pdf FontType="Embed" AllowPrinting="true" />
<Pdf DefaultFontFamily="Arial Unicode MS" />
</ExportSettings>
<ClientSettings AllowGroupExpandCollapse="True" Selecting-AllowRowSelect="true">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView
CommandItemDisplay="TopAndBottom" Dir="RTL" AllowFilteringByColumn="true"
DataKeyNames="AccessPesrmission_ID"
NoDetailRecordsText="??? ?????? ???? ????? !"
NoMasterRecordsText="??? ?????? ???? ????? !">
<CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="????? ????? ????" ShowAddNewRecordButton="false" 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 Display="false" FilterControlWidth="10px" DataField="AccessPesrmission_ID" DataType="System.Int32" FilterControlAltText="Filter AccessPesrmission_ID column" HeaderText="?????" SortExpression="AccessPesrmission_ID" UniqueName="AccessPesrmission_ID" AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True" CurrentFilterFunction="Contains">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn DataField="AccessPermission_Read" DataType="System.Boolean" FilterControlAltText="Filter AccessPermission_Read column" HeaderText="?????" SortExpression="AccessPermission_Read" UniqueName="AccessPermission_Read" AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True" CurrentFilterFunction="Contains">
</telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="AccessPermission_Add" DataType="System.Boolean" FilterControlAltText="Filter AccessPermission_Add column" HeaderText="???" SortExpression="AccessPermission_Add" UniqueName="AccessPermission_Add">
</telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="AccessPermission_Edit" DataType="System.Boolean" FilterControlAltText="Filter AccessPermission_Edit column" HeaderText="??????" SortExpression="AccessPermission_Edit" UniqueName="AccessPermission_Edit">
</telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="AccessPermission_Delete" DataType="System.Boolean" FilterControlAltText="Filter AccessPermission_Delete column" HeaderText="???" SortExpression="AccessPermission_Delete" UniqueName="AccessPermission_Delete">
</telerik:GridCheckBoxColumn>
<telerik:GridBoundColumn Display="false" FilterControlWidth="10px" DataField="AccessPesrmission_SatheSazmani_ID" FilterControlAltText="Filter AccessPesrmission_SatheSazmani_ID column" HeaderText="????? ??? ???????" SortExpression="AccessPesrmission_SatheSazmani_ID" UniqueName="AccessPesrmission_SatheSazmani_ID" AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True" CurrentFilterFunction="Contains">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="VahedSazmani_FarsiName" FilterControlAltText="Filter VahedSazmani_FarsiName column" HeaderText="???? ???????" SortExpression="VahedSazmani_FarsiName" UniqueName="VahedSazmani_FarsiName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="Semat_Name" FilterControlAltText="Filter Semat_Name column" HeaderText="???" SortExpression="Semat_Name" UniqueName="Semat_Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="GrooheKarmandi_NameFarsi" FilterControlAltText="Filter GrooheKarmandi_NameFarsi column" HeaderText="???? ???????" SortExpression="GrooheKarmandi_NameFarsi" UniqueName="GrooheKarmandi_NameFarsi">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="Personel_NameKamel" FilterControlAltText="Filter Personel_NameKamel column" HeaderText="?????" SortExpression="Personel_NameKamel" UniqueName="Personel_NameKamel">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="40px" DataField="COM_Name" FilterControlAltText="Filter COM_Name column" HeaderText="????" SortExpression="COM_Name" UniqueName="COM_Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="70px" DataField="Source_Desc" FilterControlAltText="Filter Source_Desc column" HeaderText="????" SortExpression="Source_Desc" UniqueName="Source_Desc">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn FilterControlWidth="20px" DataField="SourceType_Desc" FilterControlAltText="Filter SourceType_Desc column" HeaderText="??? ????" SortExpression="SourceType_Desc" UniqueName="SourceType_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="COM_ID" EditFormType="Template" PopUpSettings-Modal="true" FormTableStyle-HorizontalAlign="Center" FormCaptionStyle-HorizontalAlign="Center" PopUpSettings-CloseButtonToolTip="????" UserControlName="popupform" PopUpSettings-Width="800">
<EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
<FormTableStyle HorizontalAlign="Center"></FormTableStyle>
<FormCaptionStyle HorizontalAlign="Center"></FormCaptionStyle>
<FormTemplate>
</FormTemplate>
<PopUpSettings Modal="True" Width="800px" CloseButtonToolTip="????"></PopUpSettings>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox" />
</telerik:RadGrid>
</div>
<asp:SqlDataSource ID="SqlDataSource_Grid" runat="server" ConnectionString="<%$ ConnectionStrings:PigisConnectionString %>">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCompany" Name="COM_ID" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlVahedSazmani" Name="VahedSazmani_ID" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</telerik:RadAjaxPanel>
我使用以下函数将数据加载到RadGrid。 (我在页面加载中调用该函数)
void LoadData()
{
SqlDataSource_Grid.SelectParameters.Clear();
SqlDataSource_Grid.SelectCommand = "spSCT_Select_From_SCT_AccessPermission";
SqlDataSource_Grid.DataBind();
RadGrid1.DataSource = SqlDataSource_Grid;
RadGrid1.Rebind();
}
答案 0 :(得分:5)
请在你的radgrid中添加NeedDatasource事件。
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
</telerik:RadGrid>
您的C#代码:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
SqlDataSource_Grid.SelectParameters.Clear();
SqlDataSource_Grid.SelectCommand = "spSCT_Select_From_SCT_AccessPermission";
SqlDataSource_Grid.DataBind();
RadGrid1.DataSource = SqlDataSource_Grid;
}
它会在需要时自动重新绑定/数据绑定您的radgrid。请查看以下链接以获取更多信息。 Commands that invoke Rebind() implicitly
答案 1 :(得分:0)
您需要使用RadGrid1_NeedDataSource方法,告诉您的网格他的数据源应该是什么,并确保在操作方法结束时调用Radgrid1.Rebind()