I have a grid with
CommandItemDisplay
="Top"
The command bar has an insert button and a refresh button, it all seems to work ok. The problem is when there are no rows to display in the grid and I want to add one, the commandbar isnt visible so I cant add any rows !
Is there a way around this problem ? Can I have the command bar visible even when there are no rows to display in the grid ?
7 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 17 Oct 2008, 07:00 AM
Hello Mark,
I tried this at my end and the CommandItem always display regardless of records present or not in the grid. But the whole grid can vanish if at all the DataSource is set as:
If that is the case, then you can add the following code instead which will render the CommandItemDisplay.
Thanks
Princy.
I tried this at my end and the CommandItem always display regardless of records present or not in the grid. But the whole grid can vanish if at all the DataSource is set as:
RadGrid1.DataSourceID = ""; or RadGrid1.DataSourceID = string.Empty; |
If that is the case, then you can add the following code instead which will render the CommandItemDisplay.
if (RadGrid1.DataSourceID == "") |
{ |
RadGrid1.DataSource = new string[] { }; |
} |
Thanks
Princy.
0
mww
Top achievements
Rank 1
answered on 17 Oct 2008, 08:14 AM
Im using DataSource not DataSourceID. Whats the difference ?
The datasource is a custom object (collection)
The datasource is a custom object (collection)
0
mww
Top achievements
Rank 1
answered on 17 Oct 2008, 09:36 AM
I tried your suggestion and it made no difference, when the grid has no data, the command bar isnt displayed. Heres how Im populating the grid
private void PopulateSecondaryCategories(long aid) |
{ |
EWDBObjects.SecondaryCategoryCollection scc = new EWDBObjects.SecondaryCategoryCollection(); |
scc = categorymanager.GetSecondaryCategories(aid); |
this.RadGridSecondaryCategories.DataSource = scc; |
this.RadGridSecondaryCategories.DataBind(); |
if (RadGridSecondaryCategories.DataSourceID == "") |
{ |
RadGridSecondaryCategories.DataSource = new string[] { }; |
} |
} |
0
Hi mark,
Please find attached a runnable project which I prepared following your scenario. Check it out and let me know if something differs in your case.
All the best,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Please find attached a runnable project which I prepared following your scenario. Check it out and let me know if something differs in your case.
All the best,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mww
Top achievements
Rank 1
answered on 17 Oct 2008, 06:14 PM
I cant see that Im doing anything differnt to your example, but the commandbar still wont display when there are no rows in the grid. Can you please look at my code and tell me if Im missing anything.
Ive used the NeedDatasource event instead of my own method for retriving data.
heres the grid code
heres how the data is retrieved
For the selected artist, no secondary categories have been entered so the grid is empty, but no commandbar !
Ive used the NeedDatasource event instead of my own method for retriving data.
heres the grid code
<telerik:RadGrid ID="RadGridSecondaryCategories" runat="server" OnNeedDataSource="RadGridSecondaryCategories_NeedDataSource" |
AutoGenerateEditColumn="True" AutoGenerateDeleteColumn="True" AllowAutomaticInserts="False" |
AllowAutomaticDeletes="False" GridLines="None" |
AllowAutomaticUpdates="False" AllowSorting="True" |
Skin="Vista" AllowMultiRowEdit="False" |
onitemcommand="RadGridSecondaryCategories_ItemCommand" |
onitemdatabound="RadGridSecondaryCategories_ItemDataBound" |
ondeletecommand="RadGridSecondaryCategories_DeleteCommand" |
oninsertcommand="RadGridSecondaryCategories_InsertCommand" |
onupdatecommand="RadGridSecondaryCategories_UpdateCommand"> |
<MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="False" OverrideDataSourceControlSorting="True" |
EditMode="InPlace" UseAllDataFields="True" > |
<Columns> |
<telerik:GridBoundColumn DataField="ID" DataType="System.Int32" HeaderText="ID" |
ReadOnly="true" Visible="false" SortExpression="ID" UniqueName="ID"> |
</telerik:GridBoundColumn> |
<telerik:GridDropDownColumn DataField="Category" |
ListTextField="Category" ListValueField="Category" HeaderText="Category" UniqueName="SecondaryCategory"> |
</telerik:GridDropDownColumn> |
</Columns> |
</MasterTableView> |
<FilterMenu EnableTheming="True"> |
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
</FilterMenu> |
</telerik:RadGrid> |
protected void RadGridSecondaryCategories_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
EWDBObjects.SecondaryCategoryCollection scc = new EWDBObjects.SecondaryCategoryCollection(); |
long aid; |
bool ok = long.TryParse(this.HiddenArtistID.Value, out aid); |
if (ok) |
{ |
scc = categorymanager.GetSecondaryCategories(aid); |
this.RadGridSecondaryCategories.DataSource = scc; |
} |
} |
0
mww
Top achievements
Rank 1
answered on 18 Oct 2008, 04:23 PM
ok, I think Ive solved this. If the datasource is null, the command bar will not display. My data retrieval function returns null if there is no data. Heres the code i used to display the command bar when the datasource is null;
protected void RadGridSecondaryCategories_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
EWDBObjects.SecondaryCategoryCollection scc = new EWDBObjects.SecondaryCategoryCollection(); |
long aid; |
bool ok = long.TryParse(this.HiddenArtistID.Value, out aid); |
if (ok) |
{ |
scc = categorymanager.GetSecondaryCategories(aid); |
if (scc != null) |
{ |
this.RadGridSecondaryCategories.DataSource = scc; |
} |
else |
{ |
if (RadGridSecondaryCategories.DataSourceID == "") |
{ |
RadGridSecondaryCategories.DataSource = new string[] { }; |
} |
} |
} |
} |
0
mww
Top achievements
Rank 1
answered on 18 Oct 2008, 04:23 PM
ok, I think Ive solved this. If the datasource is null, the command bar will not display. My data retrieval function returns null if there is no data. Heres the code i used to display the command bar when the datasource is null;
protected void RadGridSecondaryCategories_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
EWDBObjects.SecondaryCategoryCollection scc = new EWDBObjects.SecondaryCategoryCollection(); |
long aid; |
bool ok = long.TryParse(this.HiddenArtistID.Value, out aid); |
if (ok) |
{ |
scc = categorymanager.GetSecondaryCategories(aid); |
if (scc != null) |
{ |
this.RadGridSecondaryCategories.DataSource = scc; |
} |
else |
{ |
if (RadGridSecondaryCategories.DataSourceID == "") |
{ |
RadGridSecondaryCategories.DataSource = new string[] { }; |
} |
} |
} |
} |