Empty Datasource Radgrid problem

12 posts, 1 answers
  1. Ashwin Deshpande
    Ashwin Deshpande avatar
    31 posts
    Member since:
    Aug 2009

    Posted 02 Sep 2010 Link to this post

    I am trying to bind radgrid to datasource null on page load .but the grid is not showing up.
    I want the grid Headers to show even if there is no Data.
    below is the used HTML Code

     

    <telerik:RadGrid ID="rdgDepartment" runat="server" AutoGenerateColumns="False" Width="100%"

     

     

    GridLines="None" Skin="Office2007" AllowFilteringByColumn="True"

     

     

    AllowPaging="True" AllowSorting="True">

     

     

    <HeaderContextMenu EnableTheming="True">

     

     

    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

     

     

    </HeaderContextMenu>

     

     

    <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true" />

     

     

    <MasterTableView EnableNoRecordsTemplate=true ShowHeadersWhenNoRecords=true >

     

     

    <NoRecordsTemplate>

     

     

    <div style="width: 300px;">

     

    There are no records to display

    </div>

     

     

    </NoRecordsTemplate>

     

     

    <Columns>

     

     

    <telerik:GridBoundColumn DataField="DISCIP_CODE" HeaderText="Discipline Code(Staging)"

     

     

    UniqueName="DISCIP_CODE">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="DISCIP_NAME" HeaderText="Discipline Name(Staging)"

     

     

    UniqueName="DISCIP_NAME">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="SORT_ORDER" HeaderText="Discipline Sort Order(Staging)"

     

     

    UniqueName="SORT_ORDER">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="DEPT_CODE" HeaderText="Discipline Code(PTR)"

     

     

    UniqueName="DEPT_CODE">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="DEPT_DESC" HeaderText="Discipline Name(PTR)"

     

     

    UniqueName="DISP_NAME">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="DEPT_SORT_ID" HeaderText="Discipline Sort Order(PTR)"

     

     

    UniqueName="DISP_ORDER">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="STATUS" HeaderText="STATUS" UniqueName="STATUS">

     

     

    </telerik:GridBoundColumn>

     

     

    </Columns>

     

     

    </MasterTableView>

     

     

    <ClientSettings AllowDragToGroup="True">

     

     

    <Selecting AllowRowSelect="True" />

     

     

    <Scrolling AllowScroll="true" SaveScrollPosition="true" UseStaticHeaders="True" ScrollHeight="250px" />

     

     

    </ClientSettings>

     

     

    <ExportSettings>

     

     

    <Pdf FontType="Subset" PaperSize="Letter" />

     

     

    <Excel Format="ExcelML" FileExtension=".xls" />

     

     

    <Csv ColumnDelimiter="Colon" RowDelimiter="NewLine" />

     

     

    </ExportSettings>

     

     

    <FilterMenu EnableTheming="True">

     

     

    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

     

     

    </FilterMenu>

     

     

    </telerik:RadGrid>

     

  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2010 Link to this post

    Hello Ashwin,


    Set the DataSource for the grid initially as shown below to show the headers even if you have no records.

    code:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rdgDepartment.DataSource = String.Empty;
        }
    }



    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ashwin Deshpande
    Ashwin Deshpande avatar
    31 posts
    Member since:
    Aug 2009

    Posted 03 Sep 2010 Link to this post

    Thanks
  5. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 14 Jan 2011 Link to this post

    Hello Shinu,
    When I do what you say I get the following error:
    "Both DataSource and DataSourceID are defined on 'RadGrid2'.  Remove one definition."

    So what I did is call Databind() in the page load.

    if (!IsPostBack)
    {
         //to display the grid even if it is empty
         RadGrid2.DataBind();
    }
  6. Dustin
    Dustin avatar
    79 posts
    Member since:
    Oct 2012

    Posted 21 Feb 2011 Link to this post

    I noticed an issue when setting the RadGrid.DataSource = String.Empty.

    I perform client side binding and if you set the datasource to an empty string, then the ItemStyle properties don't get applied when you bind client side.
  7. Martin
    Admin
    Martin avatar
    811 posts

    Posted 25 Feb 2011 Link to this post

    Hello Dustin,

    I have noticed that my colleague Veli has already addressed the bug report that you have opened on the same topic. To make his last response available to our community, I am pasting it in this thread as well.

    "Of course. Your feedback and request have been forwarded to the dev team. I have additionally logged a PITS issue item you and other devs can vote for. You can vote here."

    Kind regards,
    Martin
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  8. Balakrishna Reddy
    Balakrishna Reddy avatar
    37 posts
    Member since:
    Oct 2012

    Posted 05 Feb 2013 Link to this post

    Hi,

    rdgDepartment.DataSource = String.Empty;


    i am using this one for initially load the radgrid with empty records.It is working fine.But when i am clicking on "Add New Record" it will not displaying any columns.So please help me to sort it out.

    Thanks in Advance.
  9. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Feb 2013 Link to this post

    Hi,

    Please make sute that you have set the DataSource to empty inside the '!IsPostBack' condition in the Page Load. Here is the sample code snippet I tried.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
        <MasterTableView CommandItemDisplay="Top">
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CustomerID">
                </telerik:GridBoundColumn>       
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadGrid1.DataSource = String.Empty;
        }
    }
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        string selectQuery1 = "select top 10 OrderID,CustomerID from Orders";
        SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
        DataTable dt1 = new DataTable();
        conn.Open();
        adapter1.Fill(dt1);
        conn.Close();
        RadGrid1.DataSource = dt1;
    }

    Please provide the code if it doesn't help.

    Thanks,
    Shinu.
  10. Balakrishna Reddy
    Balakrishna Reddy avatar
    37 posts
    Member since:
    Oct 2012

    Posted 05 Feb 2013 Link to this post

    Hi,
    i am binding  the grid dynamically..i am not using data source..So help me..
  11. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Feb 2013 Link to this post

    Hi,

    Please take a look into the following code snippet where I am binding the RadGrid dynamically without using Datasource.

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadGrid1.DataSource = String.Empty;
        }
            
    }
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSourceID = "SqlDataSource1";     
    }

    Thanks,
    Shinu.
  12. Balakrishna Reddy
    Balakrishna Reddy avatar
    37 posts
    Member since:
    Oct 2012

    Posted 06 Feb 2013 Link to this post

    hi ,
    I am not using bellow function also,
    protected
    void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
    }
    and i want to bind the Radgrid dynamically using datatable.
  13. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Feb 2013 Link to this post

    Hi,

    You can bind the grid in page load as shown below.
    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
        {
            RadGrid1.DataSource = String.Empty;
        }
       string selectQuery1 = "select top 10 OrderID,CustomerID from Orders";
        SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
        DataTable dt1 = new DataTable();
        conn.Open();
        adapter1.Fill(dt1);
        conn.Close();
        RadGrid1.DataSource = dt1;
    }

    Please provide your code if it doesn't help.


    Thanks,
    Shinu
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017