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

[Solved] Rad Grid column reordering clears out the grid's RadComboBox items.

3 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe Bailey
Top achievements
Rank 1
Joe Bailey asked on 17 Dec 2009, 07:33 PM
We have a similar page to the demo grid here: http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filteringtemplatecolumns/defaultcs.aspx In many of the columns, we have RadComboBoxes similar to the "Custom TemplateColumn Country" column.

Issue occurring / High Level:
If I move one of the columns, no postbacks occur. If I then use one of these RadComboBoxes to filter, then a postback occurs and all of the values in the drop downs (filled on prerender) are cleared out. If I then filter again (causing a postback) the values reappear. I'm not handling a certain event. Any ideas out there? Once you see the steps, it should seem obvious, but I'm not seeing it.

Any help would be great!

Steps to Reproduce:
  1. Load grid: Grid is not automatically created. I create the datasource and databind, then use the radgrid prerender to fill the drop down values in the gridboundcolumn filtertemplates.
  2. Use the mouse to move one of the columns to a new location.
  3. Use a column's filter (RadComboBox) to filter an item in the grid. (Postback occurs, calls special function on the server which again sets the datasource and rebind, then runs the radGrids prerender.
  4. Go and open one of the drop downs filled on the prerender and they're empty.
  5. If I change a filter somewhere else that causes a postback, the RadComboBoxes are refilled

ASPX.CS
protected void Page_Load(object sender, EventArgs e)
{
            if (!this.IsPostBack)
            {
                RadGridApples.DataSource = [datasource];
                RadGridApples.DataBind();
            }
}

public void GetNewResults(object sender, EventArgs e)
{
            //Update the datasource code

            RadGridApples.DataSource = [enter datasource here];
            RadGridApples.DataBind();
}

protected void RadGridApples_PreRender(object sender, EventArgs e)
        {
            foreach (GridFilteringItem filter in RadGridApples.MasterTableView.GetItems(GridItemType.FilteringItem))
            {
                #region Drop Down
                radComboBoxApples = (RadComboBox)filter.FindControl("radComboBoxApples");
                if (radComboBoxApples != null)
                {
                    radComboBoxApples.ClearSelection();
                    radComboBoxApples.DataSource = Enum.GetNames(typeof(Apples)).ToList();
                    radComboBoxApples.DataBind();
                }

ASPX

Grid information:
<telerik:RadGrid ID="RadGridApples" runat="server" AllowFilteringByColumn="True"
  AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
  GridLines="None" onprerender="RadGridApples_PreRender" Width="100%"
  PageSize="5" OnPageIndexChanged="RadGridApples_PageIndexChanged"
  OnSortCommand="GetNewResults" OnPageSizeChanged="GetNewResults" Skin="Outlook"
     >

Example column:
<telerik:GridBoundColumn HeaderText="Apples" UniqueName="appleCombo"
      DataField="Apple"
      SortAscImageUrl="\App_Themes\XYZ\img\RadGrid\SortAsc.gif"
      SortDescImageUrl="\App_Themes\XYZimg\RadGrid\SortDesc.gif"
      SortExpression="Apple"
      >
      <HeaderStyle Width="90px" />
      <ItemStyle HorizontalAlign="Left" Width="90px"></ItemStyle>
      <FilterTemplate>
        <telerik:RadComboBox ID="RadComboBoxApples" runat="server" AutoPostBack="True" AppendDataBoundItems="true" Width="100%" OnSelectedIndexChanged="GetNewResults">
          <Items>
            <telerik:RadComboBoxItem Text="" Value="" />
          </Items>
        </telerik:RadComboBox>
      </FilterTemplate>
    </telerik:GridBoundColumn>

Client Settings in the grid:
<ClientSettings AllowColumnsReorder="True"
    AllowRowHide="True" AllowRowsDragDrop="True" ReorderColumnsOnClient="True">
    <Selecting AllowRowSelect="True" />
    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
    <Resizing AllowColumnResize="True" ClipCellContentOnResize="False" />
  </ClientSettings>


3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Dec 2009, 07:34 AM
Hi,

Could you check if the scenario works using the RadGrid AdvancedDataBinding technique .You need to bind the grid in the NeedDataSource event and the filter template dropdown in the ItemCreated event instead of the PreRender event.. This way the dropdown will be populated on every postback. In the selected index changed event of the filter dropdown you then need to call the Rebind method of the RadGrid after you appply your filter.

Please  let me know  if this was helpful.


Thanks,
Princy
0
Joe Bailey
Top achievements
Rank 1
answered on 18 Dec 2009, 01:58 PM
Princy,

Thanks! I'll give it a try. I'll work on it some today. After today, I'll be out until after the Christmas. So, please don't be offended if you don't hear anything from me until after the break. Happy Holidays.

Joe
0
Joe Bailey
Top achievements
Rank 1
answered on 30 Dec 2009, 03:23 PM

Princy,

Thanks for your response! It did work. Had to rewrite a lot of my stuff, but in the end, I reduced a lot of the code I had.

Essentially, here's the review;

  • Was able to remove a lot of miscellaneous event functions by using the NeedDataSource
  • Used the grids itemcreated like you mentioned. This was firing each time the grid was loaded.
  • Removed all of my code from the prerender
  • Removed the databinding and datasource from the page load.

 

Thanks again, as this did resolve the issue.

Note: This Telerik page also helped as well: http://www.telerik.com/help/aspnet-ajax/grddistinguishdifferencesbetweenitemcreateditemdatabound.html

Joe

Tags
Grid
Asked by
Joe Bailey
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Joe Bailey
Top achievements
Rank 1
Share this question
or