+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / AutoGenerateColumns="False" Causes Empty RadGrid on Databind

AutoGenerateColumns="False" Causes Empty RadGrid on Databind

3 posts, 0 answered
  1. RSewell
    RSewell avatar
    54 posts
    Registered:
    25 Apr 2007
    24 Jul 2012
    Link to this post
    I have the following RadGrid that, if AutoGenerateColumns="True" then the grid will bind with the datasource and show the data, but if set to false will not bind and will show the NoRecordsTemplete value, even though the datatable has rows.  What causes this, and how can I fix it?

    Oh, and the date does not get formatted, it keeps the time part, which I'd like to get rid of.
    <telerik:RadGrid ID="RadGrid1" runat="server" Width="450px" AutoGenerateColumns="false">
        <MasterTableView DataKeyNames="eDate" AutoGenerateColumns="false">
            <NoRecordsTemplate>No records found.</NoRecordsTemplate>
            <DetailTables>
                <telerik:GridTableView runat="server">
                    <GroupByExpressions>
                        <telerik:GridGroupByExpression>
                            <GroupByFields>
                                <telerik:GridGroupByField FieldName="eDate" FormatString="{0:MM/dd/yyyy}" />
                            </GroupByFields>
                        </telerik:GridGroupByExpression>
                    </GroupByExpressions>
                    <Columns>
                        <telerik:GridBoundColumn HeaderText="Date" DataField="eDate" HtmlEncode="false" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}" />
                        <telerik:GridBoundColumn HeaderText="File" DataField="file" />
                        <telerik:GridBoundColumn HeaderText="Hits" DataField="hits" />
                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
        </MasterTableView>
    </telerik:RadGrid>

    The Radgrid is being populated after a button press by the following code:
    DataTable dt = new DataTable();
    using (SqlConnection sqlConn = new SqlConnection(ConfigurationManager.AppSettings["SQLSvr"])) {
        sqlConn.Open();
        string query = "SELECT [eDate], [File], [Hits]";
        query += " FROM [MyTable]";
        SqlCommand cmd = new SqlCommand(query, sqlConn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        RadGrid1.DataSource = dt;
        RadGrid1.DataBind();
        sqlConn.Close();
    }

  2. Vivek
    Vivek avatar
    1 posts
    Registered:
    20 Mar 2013
    31 May 2013 in reply to RSewell
    Link to this post
    I'm also facing the same problem, please let me know why it's happening.

    Please reply asap.
  3. Andrey
    Andrey avatar
    14 posts
    Registered:
    29 Sep 2016
    05 Jun 2013
    Link to this post
    Hi,

    If you set the AutoGenerateColumns property to false and you do not have manually defined columns there will be no columns in RadGrid. Since there are no columns there will be no records because records are cells of given columns. Since there are no rows in the Grid the NoRecordsToDisplay message will be shown.

    How do you expect the Grid to be shown when there are no columns?

    Regards,
    Andrey
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
3 posts, 0 answered