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

Rebind not working in User Control

9 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TAD RHODES
Top achievements
Rank 1
TAD RHODES asked on 17 Dec 2009, 09:59 PM
Okay, I have to be missing something very simple here, but I've banged my head enough and need some help.

I have a user control and a simple master/detail grid placed in it.
I have placed custom filter controls in the header.

Problem:
When the user control loads into my page, the grid is populated just fine (approximately 99 rows returned).  I then select an OrderNumber from my custom filter combo box and the grid rebinds perfectly.  I have one row returned, which is exactly what is expected.  However, when I go to the same combo box filter and select "All", I get no rows returned.  However, while debugging, I can clearly see the datasource being reset to the original 99 rows returned.  I have tried this with NeedDataSource event handling and without (meaning I brute force it to rebind).

I can make this work without any problems if I place the grid directly into an aspx page, but for some reason I'm having a hard time when its inside a user control.

Below is the code pertaining to this issue.  Any help would be appreciated.  One other thing, I have tried turning off viewstate (not really an option since I need viewstate), setting datasources to null, rebinding, not forcing rebind.......etc.....etc......etc....

<telerik:RadGrid ID="rgvOrderHistory" runat="server" AllowPaging="True" 
AllowCustomPaging="true" OnSortCommand="rgvOrderHistory_SortCommand" AllowSorting="true" OnItemDataBound="rgvOrderHistory_ItemDataBound"
 
    <MasterTableView DataKeyNames="OrderNumber" AllowPaging="true" PageSize="10" PagerStyle-AlwaysVisible="true"  
        PagerStyle-Mode="NextPrev" AutoGenerateColumns="false" AllowFilteringByColumn="true"
         
        <DetailTables> 
            <telerik:GridTableView DataKeyNames="OrderNumber" Name="OrderDetails" Width="100%" runat="server" AllowSorting="true" 
            AllowPaging="true" PageSize="10" PagerStyle-AlwaysVisible="true" AllowCustomPaging="true" PagerStyle-Mode="NextPrev" AutoGenerateColumns="false">  
             <Columns> 
                    <telerik:GridBoundColumn SortExpression="Description" HeaderText="Description" HeaderButtonType="TextButton" 
                        DataField="Description"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="QuantityOrdered" HeaderText="Quantity Ordered" HeaderButtonType="TextButton" HeaderStyle-HorizontalAlign="Center" 
                        DataField="QuantityOrdered" ItemStyle-HorizontalAlign="Center" > 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="ShortSku" HeaderText="SKU" HeaderButtonType="TextButton" HeaderStyle-HorizontalAlign="Center" 
                        DataField="ShortSku" ItemStyle-HorizontalAlign="Center"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="SalesPrice" HeaderText="Sales Price" HeaderButtonType="TextButton" HeaderStyle-HorizontalAlign="Center" 
                        DataField="SalesPrice" DataFormatString="{0:c}" ItemStyle-HorizontalAlign="Center"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="ExtendedPrice" HeaderText="Ext Price" HeaderButtonType="TextButton" HeaderStyle-HorizontalAlign="Center" 
                        DataField="ExtendedPrice" DataFormatString="{0:c}" ItemStyle-HorizontalAlign="Center"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="OrderTrackingNumber" HeaderText="Tracking Number" HeaderButtonType="TextButton" HeaderStyle-HorizontalAlign="Center" 
                        DataField="OrderTrackingNumber" ItemStyle-HorizontalAlign="Center"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="DetailStatus" HeaderText="Order Status" HeaderButtonType="TextButton" HeaderStyle-HorizontalAlign="Center" 
                        DataField="DetailStatus" ItemStyle-HorizontalAlign="Center"
                    </telerik:GridBoundColumn> 
                </Columns>     
            </telerik:GridTableView>         
        </DetailTables> 
                 
            <NoRecordsTemplate> 
                        <strong><asp:Label ID="lblNoRecords" runat="server" Text="No available orders."></asp:Label></strong>                    
            </NoRecordsTemplate> 
            <Columns> 
                    <telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Order Date" HeaderButtonType="TextButton" 
                        DataField="OrderDate" DataFormatString="{0:d}"
                        <FilterTemplate>     
                        <telerik:RadDatePicker ID="rdpFilterFromDate" runat="server" MaxDate="9999-12-31 11:59:59 PM"   
                             AutoPostBack="true" OnSelectedDateChanged="rdpFilterFromDate_SelectedDateChanged" > 
                        </telerik:RadDatePicker>  
                         to    
                        <telerik:RadDatePicker ID="rdpFilterToDate" runat="server" MaxDate="9999-12-31 11:59:59 PM"  
                             AutoPostBack="true" OnSelectedDateChanged="rdpFilterToDate_SelectedDateChanged" > 
                        </telerik:RadDatePicker>                             
                    </FilterTemplate> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="OrderNumber" HeaderText="Order Number" HeaderButtonType="TextButton" HeaderStyle-HorizontalAlign="Center" 
                        DataField="OrderNumber" ItemStyle-HorizontalAlign="Center" UniqueName="OrderNumber"
                        <FilterTemplate>   
                            <telerik:RadComboBox ID="cbxFilterOrderNumber"  
                                                 DataTextField="OrderNumber"  
                                                 DataSource='<%# GetOrderDropDown()%>'  
                                                 OnSelectedIndexChanged="cbxFilterTypes_SelectedIndexChanged"  
                                                 DataValueField="OrderNumber"  
                                                 Height="200px"  
                                                 AppendDataBoundItems="true"  
                                                 SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("OrderNumber").CurrentFilterValue %>'   
                                                 runat="server"  
                                                 AutoPostBack="true"  
                                                 OnClientSelectedIndexChanged="TitleIndexChanged">   
                                <Items>   
                                    <telerik:RadComboBoxItem Value="-1" Text="All" />  
                                </Items>   
                            </telerik:RadComboBox>   
                            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">   
   
                                <script type="text/javascript">   
                                    function TitleIndexChanged(sender,args) {   
                                        var tableView=$find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");   
                                        tableView.filter("OrderNumber",args.get_item().get_value(),"EqualTo");                      
                                    }   
                                </script>   
                            </telerik:RadScriptBlock>   
                        </FilterTemplate>   
 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="Total" HeaderText="Order Total" HeaderButtonType="TextButton" HeaderStyle-HorizontalAlign="Center" 
                        DataField="Total" DataFormatString="{0:c}" ItemStyle-HorizontalAlign="Center"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="OrderType" HeaderText="Order Type" HeaderButtonType="TextButton" HeaderStyle-HorizontalAlign="Center" 
                        DataField="OrderType" ItemStyle-HorizontalAlign="Center"
                    </telerik:GridBoundColumn> 
                </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 


Now the relevant code behind (this is the way I last tried...brute force):
protected void Page_Load(object sender, EventArgs e) 
        { 
             
            if (!IsPostBack) 
            { 
                ViewState[GRIDSORTDIRECTION] = "DESC"; 
                ViewState[GRIDSORTORDER] = "OrderDate"; 
                ViewState[FILTERFROMDATE] = null; 
                ViewState[FILTERTODATE] = null; 
                ViewState[FILTERTONUMBER] = null; 
                 
                Guid g = new Guid("A2E02D63-2B56-42F8-95C7-DC98DFCCB146"); 
                _BOUserAccount = new BOUserAccount(g); 
                Session["BOUserAccount"] = _BOUserAccount; 
 
                GetOrderHistoryDataSource(true); 
            } 
        } 
 
protected void GetOrderHistoryDataSource(bool bindIt) 
        { 
            DateTime? fromDate = nulltoDate = null
            int? orderNumber = null
            if (ViewState[FILTERFROMDATE] != null) 
            { 
                fromDate = Convert.ToDateTime(ViewState[FILTERFROMDATE]); 
            } 
            if (ViewState[FILTERTODATE] != null) 
            { 
                toDate = Convert.ToDateTime(ViewState[FILTERTODATE]); 
            } 
            if (ViewState[FILTERTONUMBER] != null) 
            { 
                orderNumber = Convert.ToInt32(ViewState[FILTERTONUMBER]); 
            } 
            BOUserAccount boUserAccount2 = (BOUserAccount)Session["BOUserAccount"]; 
            int orderCount; 
            rgvOrderHistory.DataSource = boUserAccount2.GetOrderHistory(boUserAccount2.UserID, false, ViewState[GRIDSORTORDER].ToString(), 
                                                                        ViewState[GRIDSORTDIRECTION].ToString(), rgvOrderHistory.PageSize, rgvOrderHistory.CurrentPageIndex 
                                                                        , out orderCount, fromDate, toDate, orderNumber); 
            rgvOrderHistory.VirtualItemCount = orderCount
 
            if (bindIt) 
            { 
                rgvOrderHistory.Rebind(); 
            } 
        } 
 
protected List<OrderHeaderHistory> GetOrderDropDown() 
        { 
            BOUserAccount boUserAccount2 = (BOUserAccount)Session["BOUserAccount"]; 
            int orderCount; 
            return boUserAccount2.GetOrderHistory(boUserAccount2.UserID, true, "OrderNumber","ASC", null, null, out orderCount, null, null, null); 
        } 
 
protected void cbxFilterTypes_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
        { 
            ViewState[FILTERTONUMBER] = e.Value == "-1" ? null : e.Value; 
            oFilterValue = e.Value; 
 
            string filterExpression = "([OrderNumber] = '" + e.Value + "')"; 
 
            rgvOrderHistory.MasterTableView.FilterExpression = filterExpression
            GetOrderHistoryDataSource(true); 
            //rgvOrderHistory.MasterTableView.DataSource = null
            //rgvOrderHistory.MasterTableView.Rebind(); 
            //rgvOrderHistory.Rebind(); 
        } 

9 Answers, 1 is accepted

Sort by
0
TAD RHODES
Top achievements
Rank 1
answered on 18 Dec 2009, 06:53 PM
Shoot, I now can't get this to work in a regular aspx page.  What am I doing wrong?
0
TAD RHODES
Top achievements
Rank 1
answered on 22 Dec 2009, 02:31 PM
Any ideas?
0
Pavlina
Telerik team
answered on 22 Dec 2009, 04:04 PM
Hi TAD,

Complex features like hierarchy, grouping, custom edit forms, etc. are supported with advanced binding with NeedDataSource handling or data source controls only. Hence you will need to modify your logic to utilize one of these binding modes and build your hierarchy grid.

I recommend you examine the following help articles:
Hierarchical data-binding using declarative relations
Hierarchical data-binding using DetailTableDataBind event

Let me know if this helps.

All the best,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
TAD RHODES
Top achievements
Rank 1
answered on 22 Dec 2009, 07:03 PM
Pavlina,

I don't think I explained my issue correctly.  Let me start over and see if this better explains it.

I have a grid (in the code block below).  I have taken out the detail binding, because it really doesn't matter.  I have my own custom filters in the header.  I have a combo box that I fill with data from a function in code behind.  I am using Need datasource and grid.Rebind().  Here are the steps to reproduce:
1) Page loads with approximately 99 rows (i'm using my own paging as well, so I display 10 of 99 rows with virtualitemcount).
2) I choose a value in the filter combo box.
3) The page reloads a fills the grid with the one value I choose from the filter combo box.
4) I now choose "All" from the filter combo box.
5) The grid displays no records found; there is the problem.

I can see while debugging that the datasource is actually being set to the original 99 records, but the grid won't display them.  The need datasource is firing as expected and the postback is occurring correctly with the selected index change on the filter combo box.  Just can't figure out why the grid won't show the results of "All".

ASPX Page:
<telerik:RadGrid ID="rgvOrderHistory"  
                 runat="server"  
                 AllowPaging="True" 
                 AllowCustomPaging="true"  
                 OnSortCommand="rgvOrderHistory_SortCommand"  
                 AllowSorting="true"  
                 OnNeedDataSource="rgvOrderHistory_NeedDataSource"  
                 OnItemDataBound="rgvOrderHistory_ItemDataBound"
    <MasterTableView DataKeyNames="OrderNumber"  
                     AllowPaging="true"  
                     PageSize="10"  
                     PagerStyle-AlwaysVisible="true"  
                     PagerStyle-Mode="NextPrev"  
                     AutoGenerateColumns="false"  
                     AllowFilteringByColumn="true"
            <Columns> 
                    <telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Order Date" HeaderButtonType="TextButton" 
                        DataField="OrderDate" DataFormatString="{0:d}"
                        <FilterTemplate>     
                        <telerik:RadDatePicker ID="rdpFilterFromDate" runat="server" MaxDate="9999-12-31 11:59:59 PM"   
                             AutoPostBack="true" OnSelectedDateChanged="rdpFilterFromDate_SelectedDateChanged" > 
                        </telerik:RadDatePicker>  
                         to    
                        <telerik:RadDatePicker ID="rdpFilterToDate" runat="server" MaxDate="9999-12-31 11:59:59 PM"  
                             AutoPostBack="true" OnSelectedDateChanged="rdpFilterToDate_SelectedDateChanged" > 
                        </telerik:RadDatePicker>                             
                    </FilterTemplate> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="OrderNumber" HeaderText="Order Number" HeaderStyle-HorizontalAlign="Center" 
                        DataField="OrderNumber" ItemStyle-HorizontalAlign="Center" UniqueName="OrderNumber"
                        <FilterTemplate>   
                            <telerik:RadComboBox ID="cbxFilterOrderNumber"  
                                                 DataTextField="OrderNumber"  
                                                 DataSource='<%# GetOrderDropDown()%>'  
                                                 OnSelectedIndexChanged="cbxFilterTypes_SelectedIndexChanged"  
                                                 DataValueField="OrderNumber"  
                                                 Height="200px"  
                                                 AppendDataBoundItems="true"  
                                                 SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("OrderNumber").CurrentFilterValue %>'   
                                                 runat="server"  
                                                 AutoPostBack="true"  
                                                 OnClientSelectedIndexChanged="TitleIndexChanged">   
                                <Items>   
                                    <telerik:RadComboBoxItem Value="-1" Text="All" />  
                                </Items>   
                            </telerik:RadComboBox>   
                            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">   
   
                                <script type="text/javascript">   
                                    function TitleIndexChanged(sender,args) {   
                                        var tableView=$find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");   
                                        tableView.filter("OrderNumber",args.get_item().get_value(),"EqualTo");                      
                                    }   
                                </script>   
                            </telerik:RadScriptBlock>   
                        </FilterTemplate>   
 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="Total" HeaderText="Order Total" HeaderStyle-HorizontalAlign="Center" 
                        DataField="Total" DataFormatString="{0:c}" ItemStyle-HorizontalAlign="Center"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="OrderType" HeaderText="Order Type" HeaderStyle-HorizontalAlign="Center" 
                        DataField="OrderType" ItemStyle-HorizontalAlign="Center"
                    </telerik:GridBoundColumn> 
                </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 

Code Behind:
protected void Page_Load(object sender, EventArgs e) 
        { 
             
            if (!IsPostBack) 
            { 
                ViewState[GRIDSORTDIRECTION] = "DESC"; 
                ViewState[GRIDSORTORDER] = "OrderDate"; 
                ViewState[FILTERFROMDATE] = null; 
                ViewState[FILTERTODATE] = null; 
                ViewState[FILTERTONUMBER] = null; 
                 
                Guid g = new Guid("A2E02D63-2B56-42F8-95C7-DC98DFCCB146"); 
                _BOUserAccount = new BOUserAccount(g); 
                Session["BOUserAccount"] = _BOUserAccount; 
            } 
        } 
 
protected void GetOrderHistoryDataSource(bool bindIt) 
        { 
            DateTime? fromDate = nulltoDate = null
            int? orderNumber = null
            if (ViewState[FILTERFROMDATE] != null) 
            { 
                fromDate = Convert.ToDateTime(ViewState[FILTERFROMDATE]); 
            } 
            if (ViewState[FILTERTODATE] != null) 
            { 
                toDate = Convert.ToDateTime(ViewState[FILTERTODATE]); 
            } 
            if (ViewState[FILTERTONUMBER] != null) 
            { 
                orderNumber = Convert.ToInt32(ViewState[FILTERTONUMBER]); 
            } 
            BOUserAccount boUserAccount2 = (BOUserAccount)Session["BOUserAccount"]; 
            int orderCount; 
            rgvOrderHistory.DataSource = boUserAccount2.GetOrderHistory(boUserAccount2.UserID, false, ViewState[GRIDSORTORDER].ToString(), 
                                                                        ViewState[GRIDSORTDIRECTION].ToString(), rgvOrderHistory.PageSize, rgvOrderHistory.CurrentPageIndex 
                                                                        , out orderCount, fromDate, toDate, orderNumber); 
            rgvOrderHistory.VirtualItemCount = orderCount
 
            if (bindIt) 
            { 
                rgvOrderHistory.Rebind(); 
            } 
        } 
 
protected void rgvOrderHistory_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
        { 
            GetOrderHistoryDataSource(false); 
        } 
 
protected List<OrderHeaderHistory> GetOrderDropDown() 
        { 
            BOUserAccount boUserAccount2 = (BOUserAccount)Session["BOUserAccount"]; 
            int orderCount; 
            return boUserAccount2.GetOrderHistory(boUserAccount2.UserID, true, "OrderNumber","ASC", null, null, out orderCount, null, null, null); 
        } 
 
        protected void cbxFilterTypes_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
        { 
            ViewState[FILTERTONUMBER] = e.Value == "-1" ? null : e.Value; 
            oFilterValue = e.Value; 
 
            string filterExpression = "([OrderNumber] = '" + e.Value + "')"; 
 
            rgvOrderHistory.MasterTableView.FilterExpression = filterExpression
            rgvOrderHistory.Rebind(); 
        } 
 
protected void rgvOrderHistory_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridFilteringItem) 
            { 
                GridFilteringItem oItem = (GridFilteringItem)e.Item; 
                RadDatePicker oFromCal = (RadDatePicker)oItem.FindControl("rdpFilterFromDate"); 
                RadDatePicker oToCal = (RadDatePicker)oItem.FindControl("rdpFilterToDate"); 
                RadComboBox oBox = (RadComboBox) oItem.FindControl("cbxFilterOrderNumber"); 
 
                oBox.SelectedValue = ViewState[FILTERTONUMBER] == null ? oFilterValue : ViewState[FILTERTONUMBER].ToString(); 
                 
                if (ViewState[FILTERFROMDATE] != null) 
                { 
                    oFromCal.SelectedDate = Convert.ToDateTime(ViewState[FILTERFROMDATE]); 
                    oToCal.MinDate = Convert.ToDateTime(ViewState[FILTERFROMDATE]); 
                } 
                if (ViewState[FILTERTODATE] != null) 
                { 
                    oToCal.SelectedDate = Convert.ToDateTime(ViewState[FILTERTODATE]); 
                } 
            } 
        } 



0
Accepted
Pavlina
Telerik team
answered on 23 Dec 2009, 02:32 PM
Hi TAD,

Please examine these articles which elaborate on this subject and let me know if they help you to achieve the desired functionality.
Filter Templates
Filter Template

Regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tad Rhodes
Top achievements
Rank 1
answered on 12 Jan 2010, 10:52 PM
Thank you for your help...I was able to get this working.
0
Aimee Rasmussen
Top achievements
Rank 1
answered on 26 May 2010, 09:32 PM
I would love to know your resolution.. having problems with grid binding and doens't seem like Telerik offered you much support..

0
Pavlina
Telerik team
answered on 27 May 2010, 12:26 PM
Hi Aimee,

Could you please elaborate a little bit more on your scenario and specify what is the exact problem that you experience with grid binding? Thus we could do our best to provide a solution.

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
Aimee Rasmussen
Top achievements
Rank 1
answered on 27 May 2010, 01:36 PM
Thanks Pavlina.. I think I figured it out tho.  The grid was binding unexpectedly but I resolved it by managing the visibility state. 

-Aimee
Tags
Grid
Asked by
TAD RHODES
Top achievements
Rank 1
Answers by
TAD RHODES
Top achievements
Rank 1
Pavlina
Telerik team
Tad Rhodes
Top achievements
Rank 1
Aimee Rasmussen
Top achievements
Rank 1
Share this question
or