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

No records to display in radgrid

2 Answers 409 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Soumya
Top achievements
Rank 1
Soumya asked on 26 Jul 2012, 11:15 AM
I am binding grid using Needdatasource event.It works fine in normal case.
I have filter textbox for one of my column and I am validating the filter values in the ItemCommand event.Data is being fetched for the given filter value and could see the data in the Radgrid.DataSource.But the grid shows no records to display.Why the grid is not bind with the fetched data?

Please find below my code.
<telerik:RadGrid ID="gvPhoneInq" runat="server" CellSpacing="0" GridLines="None"
        AllowSorting="True" AllowFilteringByColumn="True" AllowPaging = "True"
        AutoGenerateColumns="False"  OnNeedDataSource="gvPhoneInq_NeedDataSource"
        OnItemCommand="gvPhoneInq_ItemCommand" OnSelectedIndexChanged="gvPhoneInq_SelectedIndexChanged" >      
        <PagerStyle Mode="NextPrevAndNumeric"/>
        <GroupingSettings CaseSensitive="false" />
        <ClientSettings EnablePostBackOnRowClick="true">         
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
 
        <MasterTableView CommandItemDisplay="Top" NoMasterRecordsText="No Phone enquiry records exist!"  CommandItemStyle-BackColor="lightblue" CommandItemStyle-Font-Bold="true" GridLines="None" DataKeyNames="Ph_EnqID"
              >
 <Columns>
<telerik:GridBoundColumn HeaderText="Mobile No" UniqueName="Ph_PhNo" DataField="Ph_PhNo"   >
                    <FilterTemplate>
                        <telerik:RadTextBox ID="RTMob" runat="server" Width="200px" ClientEvents-OnValueChanged="ValueChanged1" ></telerik:RadTextBox>
                        <telerik:RadScriptBlock ID="RBMob" runat="server">
 
                                <script type="text/javascript">
                                    function ValueChanged1(sender, args) {
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                        var Name = $find('<%# ((GridItem)Container).FindControl("RTMob").ClientID %>');
 
                                        tableView.filter("Ph_PhNo", Name, "EqualTo");
                                    }                                  
                                </script>
 
                            </telerik:RadScriptBlock>
                    </FilterTemplate>
                </telerik:GridBoundColumn>
</Columns>
<EditFormSettings >
            <EditColumn UniqueName="EditCo

mmandColumn1"
></EditColumn>           
            </EditFormSettings>           
 
            <CommandItemStyle BackColor="LightBlue" Font-Bold="True"></CommandItemStyle>
        </MasterTableView>       
    </telerik:RadGrid>

aspx.cs

protected void gvPhoneInq_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
  
            _phoneEnqServices = new PhoneEnqServices();
  
            gvPhoneInq.DataSource = _phoneEnqServices.GetAllPatients(search);
        }    
  
         
        protected void gvPhoneInq_ItemCommand(object sender, GridCommandEventArgs e)
        {
              
            if (e.CommandName == RadGrid.FilterCommandName)
            {
                Pair filterPair = (Pair)e.CommandArgument;
                switch (filterPair.Second.ToString())
                {
                      
                    case ("Ph_PhNo"):
                        {
                            flagD = 0;
                            RadTextBox searchMob = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].FindControl("RTMob") as RadTextBox;
                            search = " where Ph_PhNo ='" + searchMob.Text + "'";
                            break;
                        }
                }
            }          
              
        }


Please let me know if the above code has anu issues.without filter the grid binds properly.
Thanks,
Soumya

2 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 31 Jul 2012, 09:22 AM
Hello Soumya,

With your current approach the grid is actually filtered twice - once by your custom logic and a second time by its filtering functionality. What happens is that after you assign it a datasource, it uses its own filter expression (gvPhoneInq.MasterTableView.FilterExpression) to filter the provided set of data.
To avoid this, you could try either resetting the filter expression in NeedDataSource (set it to empty string) or cancel the actual filtering command (set e.Canceled=true in ItemCommand and call gvPhoneInq.Rebind()).

Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Preetham
Top achievements
Rank 2
answered on 23 Aug 2012, 09:56 AM
Please also clarify the query in this below thread
No records to display

I am not sure why is this happening.. !!
Tags
Grid
Asked by
Soumya
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Preetham
Top achievements
Rank 2
Share this question
or