This is a migrated thread and some comments may be shown as answers.

Empty Datasource Radgrid problem

11 Answers 924 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ashwin Deshpande
Top achievements
Rank 1
Ashwin Deshpande asked on 03 Sep 2010, 04:55 AM
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>

 

11 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Sep 2010, 07:16 AM
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.
0
Ashwin Deshpande
Top achievements
Rank 1
answered on 03 Sep 2010, 07:35 AM
Thanks
0
Jonx
Top achievements
Rank 2
answered on 14 Jan 2011, 11:35 PM
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();
}
0
Dustin
Top achievements
Rank 1
answered on 21 Feb 2011, 07:30 PM
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.
0
Martin
Telerik team
answered on 25 Feb 2011, 10:46 AM
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!
0
Balakrishna Reddy
Top achievements
Rank 1
answered on 05 Feb 2013, 07:53 AM
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.
0
Shinu
Top achievements
Rank 2
answered on 05 Feb 2013, 08:10 AM
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.
0
Balakrishna Reddy
Top achievements
Rank 1
answered on 05 Feb 2013, 08:13 AM
Hi,
i am binding  the grid dynamically..i am not using data source..So help me..
0
Shinu
Top achievements
Rank 2
answered on 06 Feb 2013, 12:46 PM
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.
0
Balakrishna Reddy
Top achievements
Rank 1
answered on 06 Feb 2013, 01:25 PM
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.
0
Shinu
Top achievements
Rank 2
answered on 07 Feb 2013, 07:42 AM
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
Tags
Grid
Asked by
Ashwin Deshpande
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ashwin Deshpande
Top achievements
Rank 1
Jonx
Top achievements
Rank 2
Dustin
Top achievements
Rank 1
Martin
Telerik team
Balakrishna Reddy
Top achievements
Rank 1
Share this question
or