Problem getting and filtering from the headers of a radgrid, which is loaded dynamically via sql server views.

1 Answer 56 Views
ComboBox Grid
Mediapost
Top achievements
Rank 1
Mediapost asked on 15 Sep 2023, 07:20 AM

DLL: Progress Telerik UI ASP NET AJAX VersiĆ³n 2020.2.617.40

Hi!,
I have a problem with dynamically loading data, and subsequently filtering data from the headers of a radgrid.

The radgrid data is loaded dynamically through the selection of a radcombo with Id "rcb_Views", and this loads a sql server database view into a sql SqlDataSource "eds_Generic" and binds it to the grid.

The problem is that filtering by grid headers also has to be implemented, and it works if the selection in the combo does not change. But when the selection, in order to load a new data view, and regenerate all the data in the radgrid, it gives an error:

"[column] is neither a DataColumn nor a DataRelation for the DefaultView table.

The problem seems clear, and it is that it does not refresh either the model or the data, since the error column belongs to the schema of the model of the previous view, but I have not been able to solve it by changing the data source of the data, doing a rebind, etc. .

Can someone guide me on how I can correct the problem?

ASPX

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentMain" runat="Server">
    <section class="section-admin-main">
        <h1 class="page-title">
            <asp:Label ID="lblTitle" runat="server" Text="Informes"></asp:Label>
        </h1>
        <telerik:RadAjaxManagerProxy ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rcb_Views">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rcb_Views"></telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="RG_DistributorsWithoutParts"></telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="eds_Generic"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RG_DistributorsWithoutParts">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rcb_Views"></telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="RG_DistributorsWithoutParts"></telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="eds_Generic"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManagerProxy>
        <div id="div_combo">
            <telerik:RadComboBox ID="rcb_Views" runat="server" MaxHeight="200" Width="315" OnSelectedIndexChanged="rcb_Views_SelectedIndexChanged" DataSourceID="eds_ViewNames"
                DataTextField="description" DataValueField="ViewName" AutoPostBack="true" Label="Seleccione los datos a mostrar: ">
            </telerik:RadComboBox>
        </div>
        <telerik:RadGrid ID="RG_DistributorsWithoutParts" runat="server" Height="500px" AllowPaging="True" ShowFooter="True"
            AllowSorting="True" AutoGenerateColumns="True" ShowStatusBar="True" AllowFilteringByColumn="True" DataSourceID="eds_Generic" 
            OnItemCommand="RG_DistributorsWithoutParts_ItemCommand" CellSpacing="-1" Culture="es-ES" GridLines="Both">
            <GroupingSettings CaseSensitive="false" />
            <MasterTableView Width="100%" CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="false" CommandItemSettings-ShowRefreshButton="true" CommandItemSettings-ShowExportToExcelButton="true" PageSize="50">
                <CommandItemSettings ShowAddNewRecordButton="False" ShowExportToExcelButton="True"></CommandItemSettings>
                <Columns>
                </Columns>
            </MasterTableView>
            <ClientSettings>
                <Scrolling AllowScroll="true" UseStaticHeaders="false" SaveScrollPosition="false" />
                <Resizing AllowColumnResize="true" AllowResizeToFit="true" />
            </ClientSettings>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="eds_Generic" runat="server" ConnectionString="<%$ ConnectionStrings:LMSViewsConnString %>" SelectCommand="SELECT * FROM [man_participantes]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="eds_ViewNames" runat="server" ConnectionString="<%$ ConnectionStrings:LMSViewsConnString %>" SelectCommand="SELECT * FROM [v_ViewNames]"></asp:SqlDataSource>
    </section>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="FooterScripts" runat="Server">
    <style type="text/css">
        input[type="checkbox"] {
            -webkit-appearance: checkbox;
        }

        input[type="radio"] {
            -webkit-appearance: radio;
        }
    </style>

    <script type="text/javascript">
        function pageLoad() {
            var grid = $find('<%=RG_DistributorsWithoutParts.ClientID %>');
            var columns = grid.get_masterTableView().get_columns();
                for (var i = 0; i < columns.length; i++) {
                    columns[i].resizeToFit();
                }
        }
    </script>
</asp:Content>
ASPX.CS

protected void Page_Load(object sender, EventArgs e)
{
    (this.Master as BaseMaster).setVisibilityMenu(false);
    this.meth_TranslateGrids(RG_DistributorsWithoutParts);
    if (rcb_Views.SelectedValue != "")
    {
        eds_Generic.SelectCommand = "SELECT * FROM [" + rcb_Views.SelectedValue + "]";
    }

    if (!IsPostBack)
    {
        rcb_Views.DataBind();
        eds_Generic.SelectCommand = "SELECT * FROM [" + rcb_Views.SelectedValue + "]";
        RG_DistributorsWithoutParts.DataBind();
    }
}
protected void rcb_Views_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
    eds_Generic.SelectCommand = "SELECT * FROM [" + rcb_Views.SelectedValue + "]";
    RG_DistributorsWithoutParts.DataBind();
}


1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 19 Sep 2023, 11:55 AM

Hi,

To ensure that RadGrid functions correctly, especially its built-in features like filtering, sorting, paging, and exporting, it's crucial to follow proper binding procedures. You can find detailed guidance in this knowledge-based article:

Please note that RadGrid has its own internal binding process, and explicit calls to the DataBind() method should be avoided, as they can lead to issues.

I recommend the following steps:

  1. Ensure that RadGrid is bound either via its NeedDataSource event or to a declarative data source (e.g., SqlDataSource).
  2. Remove any explicit calls to the DataBind() method.

If you encounter any further problems, please let me know, and I will be happy to assist you.

Kind regards,
Doncho
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
ComboBox Grid
Asked by
Mediapost
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or