
5 Answers, 1 is accepted

DataSet ds = GetSomeData();
if (ds.Tables[0].Rows.Count == 0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
}
RadGrid1.DataSource = ds;
RadGrid1.DataBind();
Sean~

ShowHeadersWhenNoRecords and
EnableNoRecordsTemplate
properties

Thanks!
Sean

Sean, Xcalibur
Thank you both for the hints. Using both of your suggestions I did the following and included the steps and code snippets for anyone else who might need to do this:
1- Removed the DataSourceID attribute from the <radGrid> definition. This was done so that I could have the OnNeedDataSource event fired.
2- Added the OnNeedDataSource attribute to the <RadGrid>.
3- Added the <NoRecordsTemplate> to override the deafault 'No Records to display' message
4- I did not need to alter the ShowRecordsWithNoHeaders property because it defaults to true.
5- Created the NeedDataSource event to handle the initalLoad and assign it the empty dataset
Code snippets
* my RadGrid definition is now (with DataSourceID removed and OnNeedDataSource added):
<telerik:RadGrid ID="GridMedia" runat="server" AutoGenerateColumns="False" GridLines="None" AllowPaging="true" AllowMultiRowSelection="false" Skin="WebBlue" OnNeedDataSource="Grid_NeedDataSource" OnItemDataBound="Grid_ItemDataBound" OnItemCommand="Grid_ItemCommand" AllowSorting="true" PageSize="10" Height="200px">
* my needDataSource event which creates an empty dataset on the initialload
and will show the grid with no rows
protected void Grid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
if (e.RebindReason == GridRebindReason.InitialLoad)
{
DataTable emptyTable = new DataTable();
GridMedia.DataSource = emptyTable;
}
else
{
GridMedia.DataSourceID = "MediaSQLDataSource";
}
}
* a button click event that will use the datasource that returns my data
protected
void btnSearch_Click(object sender, EventArgs e)
{
// if my datasource with data has not yet been assigned,
// set it now
if (GridMedia.DataSourceID.Length == 0 )
{
GridMedia.DataSource = null;
GridMedia.DataSourceID = "MediaSQLDataSource";
}
else
{
GridMedia.DataBind();
}
}
