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
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.
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();
}
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.
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
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.
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.
i am binding the grid dynamically..i am not using data source..So help me..
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.
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.
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