I am rewriting a rather large web application with just about 100 lists in it. We have to access control the lists, and the actions performed on them so we are trying to make the creation of the lists (RadGrids) dynamic.
In the old system, we would have a XML config file for the lists and then do the HTML by hand for each list.
We would like to continue using the XML file, and with regular GridBoundColumn types it works fine. We find ourselves in some problems when we need to display 2 field names in one column, then we have to use GridTemplateColumn.
With more than 100 lists, all with different datasources, things get a bit tricky. We have implemented a simple ITemplate for 1 datasource, but because all the datasources are different, this does not seem to be a viable solution. We would have to create an eventListener for all the special columns in all the datasources, with some very tricky coding ...
Is there any way we can send into the column collection a simple string like just like when we are creating a template column in the ASPX file:
<telerik:GridTemplateColumn>Is it possible for us to use the <a href="<%#Eval("LinkUrl")%>"><%#Eval("LinkText")%></a> model to create these columns in any way ??
<ItemTemplate>
<a href="<%#Eval("LinkUrl")%>"><%#Eval("LinkText")%></a>
</ItemTemplate>
</telerik:GridTemplateColumn>
22 Answers, 1 is accepted
Please review this help topic on how to create RadGrid programmatically. At the bottom you can find how to create grid template columns dynamically.
Give it a try and let us know if you need further directions/help.
Regards,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Indeed creating only the needed columns at a time would be with better performance than declaring all columns and hiding the unnecessary once. On the other side, when a column's Visible property is set to false, this column is not being rendered on the client at all. Therefore the approach with declaring all columns initially should not affect the performance in a significant manner.
I hope this helps.
Best wishes,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'm getting the error: Cannot create column with the specified type name: GridCalculatedColumn.
Is the creation of calculated columns at runtime supported? I really hope it is!
If it is not, what's the workaround? Am I looking at having to do it the old fashioned way and hook into the ItemDataBound event?
I followed your scenario and was able to replicate the issue. It seems that there is a problem with the ViewState of the calculated column when it is created at runtime. I forwarded the issue for further investigation and testing and hope it could be fixed soon.
As a workaround, I suggest that you set the EnableColumnsViewState property of the MasterTableView to false and create your columns on Page.Init or on each Page.Load.
Give it a try and let me know if this works for you.
All the best,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Please try the attached sample and let me know if it works as desired and what differs in your case. If you could modify the sent code so the issue is replicable and turn it, this can help us find a resolution for you.
Kind regards,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Please suggest me a solution for this issue.
Can you confirm that if you set the EnableColumnsViewState property to true, the insert form appears as expected?
I suggest that you send me your grid declaration/programmatic creation code so I could have a better look and see what could have gone wrong.
Best wishes,
Iana
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
In my project if i set EnableColumnsViewState property to true then Add New Record is working. I created a sample project to send you the sample code but in that code Add New Record is working even when i set the EnableColumnsViewState to false.
I don't understand why in project Add New Record is not working when i set EnableColumnsViewState property to false. I also noticed in my project that the NeedDataSource event is not fired when i clicked the Add New Record when(EnableColumnsViewState = false)
Please help me if you have any clue.
Best regards
Godwin
Could you please try sending the problematic page to me? You can open a formal support ticket where you could attach files.
Then I could check it out and see what could have gone wrong and how to solve it.
Looking forward your reply,
Iana
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
As suggested by you i have created a support ticket(204602) and attached sample code demonstrating the problem.
Please see if you can help,
Best regards
Godwin
Thank you for preparing a sample project and sending it to us in a formal support ticket.
I will check it out and let you know of the results there.
Greetings,
Iana
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
While there are some tantalizing hints in the references you provide, I don't see a direct answer to the question posed by Arni Gunnar Ragnarsson: is it possible to include <% # Eval("FieldName") %> dynamically in an ItemTemplate?
I'm using a RadGrid in MVC, where there are no postbacks, and I'd like to generate GridTemplateColumns like the one below dynamically in client-side script. Is this possible?
<telerik:GridTemplateColumn>
<HeaderTemplate>
<%
# Ajax.ActionLink("Column1", "Sort", new { columnName = "Column1" }, options)%>
</HeaderTemplate>
<ItemTemplate>
<%
# Eval("Column1")%>
</ItemTemplate>
<EditItemTemplate>
<%
# Html.TextBox("Column1", Eval("Column1").ToString())%>
</EditItemTemplate>
</telerik:GridTemplateColumn>
Frank
I am afraid that RadGrid cannot be created dynamically on the client. For more information on RadGrid programmatic creation you can check this help article.
Regarding the first question: You can put in the grid ItemTemplate whatever you can put in the MS GridView's ItemTemplate for instance.
Greetings,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
iana -
per a previos your post of yours regarding the error "Cannot create column with the specified type name: GridCalculatedColumn":
"Hi Rob,
I followed your scenario and was able to replicate the issue. It seems that there is a problem with the ViewState of the calculated column when it is created at runtime. I forwarded the issue for further investigation and testing and hope it could be fixed soon.
As a workaround, I suggest that you set the EnableColumnsViewState property of the MasterTableView to false and create your columns on Page.Init or on each Page.Load.
Give it a try and let me know if this works for you."
i am also trying to dynamically create a radgrid with a calculated column and am getting the same error as rob was. has this been fixed?
my calculated column is in the markup, but i assign the DataFields and Expression property in the codebehind since the gridboundcolumns are dynamically generated. here is my code:
------------------------------
protected void InitPage()
{
ddlDestinations.FillWithEntity((new DestinationProxy()).GetAllDestinations(), true);
int n = ScrapTypes.Length;
string[] DataFields = new string[n];
string[] Expression = new string[n];
for (int i = 0; i < n; i++)
{
ScrapType ScrapType = ScrapTypes[i];
string ScrapTypeName = StripIt(ScrapType.Name);
string EditorId = "Editor" + ScrapTypeName;
GridEditableColumn col = new GridBoundColumn();
GridTemplateColumnEditor Editor = new GridTemplateColumnEditor();
rgCalendar.Columns.Add(col);
phEditors.Controls.Add(Editor);
//i build the GridCalculatedColumn properties here
DataFields[i] = ScrapTypeName;
Expression[i] = "{" + i.ToString() + "}";
((GridBoundColumn)col).DataField = ScrapTypeName;
((GridBoundColumn)col).Aggregate = GridAggregateFunction.Sum;
((GridBoundColumn)col).DataType = typeof(int);
col.UniqueName = ScrapTypeName;
col.HeaderText = ScrapType.Name;
col.ColumnEditorID = EditorId;
col.ItemStyle.Width = Unit.Pixel(100);
col.ItemStyle.Wrap = false;
Editor.ID = EditorId;
}
GridCalculatedColumn Calc = (GridCalculatedColumn)rgCalendar.Columns.FindByUniqueName("ItemTotal");
//here is where i assign those property values
Calc.Expression = string.Join("+", Expression);
Calc.DataFields = DataFields.ToArray();
rgCalendar.MasterTableView.SwapColumns("ItemTotal", StripIt(ScrapTypes[ScrapTypes.Length - 1].Name));
}
------------------------------
you previously recommended to another user that they disable viewstate, but this will affect being able to extract values from the grideditcolumns.
dynamic radgrid building has been an experience indeed. is there a resolution to this issue?
I will check the status of this issue and will let know about it correspondingly.
However, you should note that RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime. You should either create all the columns in the grid programmatically, or else define them all in the ASPX file.
Regards,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I checked it out and it seems that the issue is not solved in Q2 2009 version release of RadControls for ASP.NET AJAX. SO you can leave the EnableColumnsViewState property set to false.
Please excuse us for the inconvenience.
Regards,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Indeed, the issue should be fixed in the current version of RadControls for ASP.NET AJAX.
Please check the attached working sample and let me know if something differs in your case and is any issues arise.
Regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I have enableview state made as false, and trying to click on save button, but in the save the data is not able to get, is there any way to extract the data
Can you specify what happens when you click the Save button? Is some error thrown, the desired data is missing?
For more information on accessing RadGrid cells and rows, you can check the below article:
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html
Regards,
Iana
the Telerik team