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

Grid not updated when changing DataSource in C#

4 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roland
Top achievements
Rank 1
Roland asked on 09 Feb 2009, 10:08 AM
Hi!

I have a problem when manuelly setting DataSource of my Grid. I habe a Tabstrip where the first tabs are used to add an remove articles to an articlelist, the last tab should display the ordered Articles in the Grid. The Problem is when i click the Tab(Article Summary) the datasource of the grid changes properly but the Grid still displays the old items.

here are my code snippets

Master Page Declaration
<telerik:RadGrid ID = "SummaryGrid" 
                             runat="server" 
                             PageSize="10" 
                             AllowSorting="true" 
                             AllowPaging="true" 
                             AllowMultiRowSelection="false" 
                             AutoGenerateColumns="false" 
                             GridLines="None" 
                             OnNeedDataSource="SummaryGridNeedsData" 
                             Skin="Telerik"
                            <PagerStyle Mode="NumericPages" /> 
                            <MasterTableView GroupLoadMode="Client" TableLayout="Fixed"
                            <Columns> 
                               some columms 
                        </Columns> 
                        <NoRecordsTemplate> 
                            <div>There are no articles to Display</div> 
                        </NoRecordsTemplate> 
                   </MasterTableView> 
                   <ClientSettings AllowGroupExpandCollapse="true" ReorderColumnsOnClient="true" AllowColumnsReorder="true" AllowDragToGroup="true"
                   <Resizing AllowRowResize="True" AllowColumnResize="True" EnableRealTimeResize="True" 
                            ResizeGridOnColumnResize="False"></Resizing> 
                   </ClientSettings> 
                 </telerik:RadGrid> 

Ajax Settings

<telerik:RadAjaxManagerProxy runat="server"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="TabStrip"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="TabStrip" /> 
                <telerik:AjaxUpdatedControl ControlID="MultiPage" /> 
                <telerik:AjaxUpdatedControl ControlID="SummaryGrid"/> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="SummaryGrid"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="SummaryGrid" /> 
             </UpdatedControls> 
        </telerik:AjaxSetting> 
</AjaxSettings> 
    </telerik:RadAjaxManagerProxy>   

DataBinding

SummaryGrid.DataSource = String.Empty; 
            List<PriceRow> pricelist = GetItems(); 
            if (pricelist != null
                SummaryGrid.DataSource = pricelist; 
I hope somebody can help me with this issue.

Greetings
Martin


4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 09 Feb 2009, 11:52 AM
Hi Martin,

Try adding the SummaryGrid.Rebind() method after setting the DataSource of the RadGrid and see whether its working for you.

SummaryGrid.DataSource = String.Empty; 
SummaryGrid.Rebind(); 
List<PriceRow> pricelist = GetItems(); 
if (pricelist != null
       SummaryGrid.DataSource = pricelist; 
       SummaryGrid.Rebind(); 

Thanks,
Shinu.
0
Roland
Top achievements
Rank 1
answered on 09 Feb 2009, 12:17 PM
Hi Shinu!

Thanks for your quick response, it solved my problem.

greetings
Martin
0
Jake
Top achievements
Rank 1
answered on 02 Mar 2009, 03:57 PM
What if your datasource is null?

In my case, I have a link button.  The user clicks it and I call rebind on several grids.  This fires the NeedDataSource event which in turn sets the datasource for my grid to null since there is no data available.  Rather than showing nothing as I would hope, it displays the old data?
0
Jake
Top achievements
Rank 1
answered on 02 Mar 2009, 04:07 PM
Never mind.  I found the answer.  You can clear the grid by setting the datasource to string.Empty.  Why you simply cannot set it to null is a little weird.  The fact that you have to set it specifically to string.Empty screams for a method.
Tags
Grid
Asked by
Roland
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Roland
Top achievements
Rank 1
Jake
Top achievements
Rank 1
Share this question
or