Hi everybody,
I try to add Columns to a RadGrid dynamically and I'm able to do it, but, when i do a post back
the RadGrid's columns are reinitialized and i don't want it. i want that my RadGrid stay
as it was before postback. Why? i want to save the columns' position and if the RadGrid
is reinitialized, I can't it.
Example:
RadGrid Status (initial):
Column1 Column2 Column3
User changes the columns' order:
Column3 Column2 Column1
User does post back and RadGrid come back to status initial.
Column1 Column2 Column3
If i do that in a page aspx (which not inherits of a masterpage), my code works, but
with a masterPage doesnt work. someone has an idea?
It's a very simple thing but i tried to do it and I'm not be able, i read all forums and i do all, but that not works in a page which inherits of a master page.
Someone can help me?
My RadGrid's code:
C# code:
I try to add Columns to a RadGrid dynamically and I'm able to do it, but, when i do a post back
the RadGrid's columns are reinitialized and i don't want it. i want that my RadGrid stay
as it was before postback. Why? i want to save the columns' position and if the RadGrid
is reinitialized, I can't it.
Example:
RadGrid Status (initial):
Column1 Column2 Column3
User changes the columns' order:
Column3 Column2 Column1
User does post back and RadGrid come back to status initial.
Column1 Column2 Column3
If i do that in a page aspx (which not inherits of a masterpage), my code works, but
with a masterPage doesnt work. someone has an idea?
It's a very simple thing but i tried to do it and I'm not be able, i read all forums and i do all, but that not works in a page which inherits of a master page.
Someone can help me?
My RadGrid's code:
| <telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="false" |
| EnableLinqExpressions="false" GridLines="None" AutoGenerateColumns="false" |
| Skin="InductDefault" EnableEmbeddedSkins="false" |
| onneeddatasource="RadGrid2_NeedDataSource"> |
| <MasterTableView AutoGenerateColumns="False" EnableNoRecordsTemplate="false" |
| HierarchyDefaultExpanded="false" HierarchyLoadMode="Client" Width="100%"> |
| </MasterTableView> |
| <ClientSettings AllowColumnHide="true" AllowColumnsReorder="true" |
| ReorderColumnsOnClient="true"> |
| </ClientSettings> |
| </telerik:RadGrid> |
C# code:
| protected void page_Init(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| { |
| createRadGrid2(); |
| } |
| } |
| public void createRadGrid2() |
| { |
| XDocument xmlDoc = XDocument.Load(RadGridXmlConfig); |
| var Columns = xmlDoc.Elements("Columns") |
| .Elements("Column") |
| .Attributes("uniqueName"); |
| foreach (var colTemp in Columns) |
| { |
| String uniqueName = colTemp.Value; |
| tableTripsDetail.Columns.Add(uniqueName); |
| RadGrid2.MasterTableView.Columns.Add(createBoundColumn(uniqueName)); |
| } |
| } |
| protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| RadGrid2.DataSource = getTableReportTripsDetail(); |
| } |
| private GridBoundColumn createBoundColumn(String valueUnique) |
| { |
| GridBoundColumn BoundColumn = new GridBoundColumn(); |
| BoundColumn.DataField = valueUnique; |
| BoundColumn.HeaderText = valueUnique; |
| BoundColumn.SortExpression = valueUnique; |
| BoundColumn.UniqueName = valueUnique; |
| return BoundColumn; |
| } |