This is a migrated thread and some comments may be shown as answers.

[Solved] Disappearing Column HeaderText After Postback

4 Answers 270 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh Horton
Top achievements
Rank 1
Josh Horton asked on 05 Feb 2010, 05:03 PM
I have a RadGrid that has it's rows and columns being created programatically, and there is a RadAjaxManager that is set to update another Panel on SelectedIndexChange. The RadGrid also has scrolling enabled and multirowselect disabled. The RadGrid operates as supposed to, but as soon as you scroll it starts collecting selected items. I have set break points and verified through watches that SelectedItems.Count grows greater that 1. This also prevents from selecting previous selected rows after you've scrolled. I have tried clearing the selected items in the page unload event, but when it renders it sometimes shows more than one item selected. I say sometimes because it is not consistent with this issue. Only pattern I have noticed is that scrolling starts the problem.

(Edited)
Disregard about the disappearing headers. Just the multiple selections issue now.

I would appreciate any advice on this. I'll include my code as well. Thanks.

P.S.  The code I've included is set up to create text for the columns and rows, so no actual data is needed. You can easily copy and paste the same code to see what I'm seeing.


<rad:RadAjaxManager ID="AjaxManager" runat="server"
 <AjaxSettings> 
  <rad:AjaxSetting AjaxControlID="grdCustomerAssignments"
   <UpdatedControls> 
    <rad:AjaxUpdatedControl ControlID="grdCustomerAssignments" /> 
   </UpdatedControls> 
  </rad:AjaxSetting> 
  <rad:AjaxSetting AjaxControlID="grdCustomerAssignments"
   <UpdatedControls> 
    <rad:AjaxUpdatedControl ControlID="pnlDetails"  /> 
   </UpdatedControls> 
  </rad:AjaxSetting> 
 </AjaxSettings> 
</rad:RadAjaxManager> 
 
<rad:RadGrid ID="grdCustomerAssignments" runat="server" Skin="WebBlue" AutoGenerateColumns="false" AllowMultiRowSelection="false" OnNeedDataSource="grdCustomerAssignments_NeedDataSource" OnSelectedIndexChanged="grdCustomerAssignments_SelectedIndexChanged"
     
 <ClientSettings EnablePostBackOnRowClick="true" > 
  <ClientEvents/> 
  <Scrolling AllowScroll="true" ScrollHeight="350" UseStaticHeaders="true" SaveScrollPosition="true" /> 
  <Selecting AllowRowSelect="true" /> 
  <Resizing AllowColumnResize="true" /> 
 </ClientSettings> 
             
 <MasterTableView DataKeyNames="ID" > 
  <HeaderStyle Wrap="false" HorizontalAlign="Center" VerticalAlign="Middle" Font-Bold="true" /> 
  <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="false" /> 
  <AlternatingItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="false" /> 
                 
  <NoRecordsTemplate> 
    <div style="font-size:80%; color:Maroon;">No Items Were Found</div> 
  </NoRecordsTemplate> 
 
 </MasterTableView> 
                 
</rad:RadGrid> 
 
<asp:Panel ID="pnlDetails" runat="server"
 <rad:RadTabStrip ID="tabStrip" runat="server" Align="Justify" AppendDataBoundItems="false" SelectedIndex="0" MultiPageID="multiPage" Skin="WebBlue"
  <Tabs></Tabs
 </rad:RadTabStrip> 
 <rad:RadMultiPage ID="multiPage" runat="server"></rad:RadMultiPage> 
</asp:Panel> 



protected
 void Page_Init(object sender, EventArgs e) 
 GetAssignments(); 
 if (!IsPostBack) 
  AddColumnsToGrid(); 
 
protected void Page_Load(object sender, EventArgs e) 
 tabStrip.Tabs.Clear(); 
 multiPage.Controls.Clear(); 
 
protected void Page_UnLoad(object sender, EventArgs e) 
 grdCustomerAssignments.MasterTableView.ClearSelectedItems(); 
 
protected void grdCustomerAssignments_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
 grdCustomerAssignments.DataSource = Assignments; 
 
protected void grdCustomerAssignments_SelectedIndexChanged(object sender, EventArgs e) 
 try 
 { 
  string id = ((RadGrid)sender).SelectedValue.ToString(); 
                 
  DataRow dataRow = null
  foreach (DataRow row in Assignments.Rows) 
  { 
   if (row["ID"].ToString() == id) 
    dataRow = row; 
  } 
 
  PopulateAssignmentDetail(dataRow); 
 
 } 
 catch (Exception ex) 
 { 
 
 } 
 
protected void PopulateAssignmentDetail(DataRow dataRow) 
 // just some code to add details to each tab. 
 
protected void AddColumnsToGrid() 
 grdCustomerAssignments.MasterTableView.Columns.Clear(); 
 
 for (int i = 1; i < 7; i++) 
 { 
  DataColumn column = Assignments.Columns[i]; 
  if (column.DataType == typeof(Int32)) 
  { 
   GridNumericColumn numericColumn = new GridNumericColumn(); 
   numericColumn.HeaderText = column.ColumnName; 
   numericColumn.DataField = column.ColumnName; 
   grdCustomerAssignments.MasterTableView.Columns.Add(numericColumn); 
  } 
  else if (column.DataType == typeof(DateTime)) 
  { 
   GridDateTimeColumn dateColumn = new GridDateTimeColumn(); 
   dateColumn.HeaderText = column.Caption; 
   dateColumn.DataField = column.ColumnName; 
   dateColumn.DataFormatString = @"{0:MMM dd yyyy}"
   grdCustomerAssignments.MasterTableView.Columns.Add(dateColumn); 
  } 
  else 
  { 
   GridBoundColumn boundColumn = new GridBoundColumn(); 
   boundColumn.HeaderText = column.Caption; 
   boundColumn.DataField = column.ColumnName; 
   grdCustomerAssignments.MasterTableView.Columns.Add(boundColumn); 
  } 
 } 
 
private void GetAssignments() 
 if (Assignments == null
  Assignments = new DataTable(); 
 if (TabTitles == null
  TabTitles = new Dictionary<string, IList<int>>(); 
 
 try 
 { 
  Assignments.Columns.Add(new DataColumn("ID")); 
  for (int i = 0; i < 50; i++) 
  { 
   Assignments.Columns.Add(new DataColumn("Column" + i.ToString())); 
  } 
   
  int columnIndex = 0; 
  int tabIndex = 0; 
  foreach (DataColumn column in Assignments.Columns) 
  { 
   if (columnIndex > 5) 
   { 
    string fieldCategory = "tab" + tabIndex.ToString(); 
    if (tabIndex == 4) 
     tabIndex = 0; 
    else 
     tabIndex++; 
 
    if (!TabTitles.ContainsKey(fieldCategory)) 
    { 
     IList<int> tmp = new List<int>(); 
     tmp.Add(columnIndex); 
     TabTitles.Add(fieldCategory, tmp); 
    } 
    else 
     TabTitles[fieldCategory].Add(columnIndex); 
   } 
   columnIndex++; 
  } 
 
  for (int j = 0; j < 50; j++) 
  { 
   DataRow row = Assignments.NewRow(); 
   foreach (DataColumn column in Assignments.Columns) 
   { 
    row[column.ColumnName] = column.ColumnName + "Row" + j.ToString(); 
   } 
   Assignments.Rows.Add(row); 
  } 
 
  Assignments.AcceptChanges(); 
 } 
 catch (Exception ex) 
 { 
 
 } 
 

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Feb 2010, 06:04 AM
Hi,

"To define the structure of a RadGrid control that is declared in the ASPX page, use the Page_Load event handler. Columns and detail table should be added to the corresponding collection first, before the values for their properties are set. This is important because no ViewState is managed for the object before it has been added to the corresponding collection."

   GridBoundColumn boundColumn; 
   boundColumn = new GridBoundColumn(); 
   RadGrid1.MasterTableView.Columns.Add(boundColumn);                
   boundColumn.DataField = "CustomerID"
   boundColumn.HeaderText = "CustomerID";

Programmatic creation

Could you try creating  your grid accordingly and  do let me know how it goes.

Thanks,
Princy
0
Josh Horton
Top achievements
Rank 1
answered on 09 Feb 2010, 04:27 PM
Yeah, I found a post on adding the column to the grid and then adding the properties. But now my issue is with selecting multiple rows even though the AllowMultipleRowSelection is set to false. The key point to make is that it only allows multiple selections after you have scrolled in the grid.

Anyone???
0
Pavlina
Telerik team
answered on 11 Feb 2010, 03:16 PM
Hi Josh,

In order to avoid this erroneous behavior, please upgrade to version 2009.3.1314 of RadControls for ASP.NET AJAX where the problem is fixed.
http://www.telerik.com/support/kb/aspnet-ajax/general/updating-radcontrols-for-asp-net-to-another-version-or-license.aspx

Sincerely yours,
Pavlina
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.
0
Josh Horton
Top achievements
Rank 1
answered on 11 Feb 2010, 04:03 PM
Great, thank you for your reply. We will be getting the latest version as soon as possible and I will post back if that fixes my issue.
Tags
Grid
Asked by
Josh Horton
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Josh Horton
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or