We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Listview not binding...showing empty list

Thread ID:

Created:

Updated:

Platform:

Replies:

147642 Sep 18,2019 12:02 PM UTC Sep 27,2019 12:56 PM UTC Xamarin.Forms 7
loading
Tags: SfListView
Vijil Stephen
Asked On September 18, 2019 12:02 PM UTC

hi,

I want to bind listview using model class filled data from httpclient request (json).. can anyone help me with sample code or tutorials.

Code behind
===========
PostContentModel postContent = new PostContentModel()
            {
                reqType = "DDDD",
                token = "TTT",
                device = "SDSDSD"
            };

            var json = JsonConvert.SerializeObject(postContent);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpClient client = new HttpClient();
            var response = await client.PostAsync("Requestsurl", content);

            newsModel objnewsModelList = new newsModel();

            if (response.IsSuccessStatusCode)    // Check the response StatusCode
            {
                string responseBody = await response.Content.ReadAsStringAsync();
                objnewsModelList = JsonConvert.DeserializeObject<newsModel>(responseBody);
               
                listView.ItemSize = 100;
                listView.ItemsSource = objnewsModelList;
                listView.ItemTemplate = new DataTemplate(() => {
                    var grid = new Grid();
                    var newstitle = new Label { FontAttributes = FontAttributes.Bold, BackgroundColor = Color.Teal, FontSize = 21 };
                    newstitle.SetBinding(Label.TextProperty, new Binding("news_title"));
                    var newsdate = new Label { BackgroundColor = Color.Teal, FontSize = 15 };
                    newsdate.SetBinding(Label.TextProperty, new Binding("news_date"));

                    grid.Children.Add(newstitle);
                    grid.Children.Add(newsdate, 1, 0);

                    return grid;
                });            
            }

Xaml View
=============
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             xmlns:sflv="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms"
             x:Class="TestApp.View.Home">
    <sflv:SfListView x:Name="listView"
                   ItemsSource="{Binding newsModel}"
                   ItemSize="100">
        <sflv:SfListView.ItemTemplate>
            <DataTemplate>
                <Grid Padding="10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="0.4*" />
                        <RowDefinition Height="0.6*" />
                    </Grid.RowDefinitions>
                    <Label Text="{Binding news_title}" FontAttributes="Bold" TextColor="Teal" FontSize="21" />
                    <Label Grid.Row="1" Text="{Binding news_date}" TextColor="Teal" FontSize="15"/>
                </Grid>
            </DataTemplate>
        </sflv:SfListView.ItemTemplate>
    </sflv:SfListView>
</ContentPage>



Sangeetha Raju [Syncfusion]
Replied On September 19, 2019 12:30 PM UTC

Hi Vijil, 
 
Thank you for contacting Syncfusion support. 
 
We have checked the reported query with the provided code snippet and found that the BindingContext is not applied. Can you please check with your sample. Also, we have attached the tested sample for your reference. Please download the sample from below link. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
Sangeetha Raju. 


Vijil Stephen
Replied On September 20, 2019 06:29 AM UTC

Thank for the reply.

But i have a post request with two parameters (token and device) for which i get a array json response.

Please help

Sangeetha Raju [Syncfusion]
Replied On September 23, 2019 12:28 PM UTC

Hi Vijil, 
 
We would like to inform you that we are not clear with your requirement where you are facing the problem. Please let us know where you are facing the problem in below use cases 
 
  • Receiving JSON data
  • Converting JSON data to model object
  • Binding the model object to ListView
 
If you are facing problem in first and second use case, you need to find generic solution on your side, it is not related to ListView. We have already prepared and updated a sample already using webAPI. So, please share the model class or json data if possible, so that we can assist you further at our end. 
 
Regards, 
Sangeetha Raju. 


Vijil Stephen
Replied On September 24, 2019 05:57 AM UTC

Hi,

Sorry...i solved that issue, forgot to close this thread.

Thanks for the support.

Sangeetha Raju [Syncfusion]
Replied On September 25, 2019 09:37 AM UTC

Hi Vijil, 
 
Thanks for the update. Please let us know if you require further assistance. 
 
Regards, 
Sangeetha Raju. 


Vijil Stephen
Replied On September 26, 2019 07:50 AM UTC

Hi,

Thanks fo the help.

Populated Listview from webapi.

Now i need to add Loadmoreitems Command and Search bar to sflistview, can anyone help.

Sangeetha Raju [Syncfusion]
Replied On September 27, 2019 12:56 PM UTC

Hi Vijil, 
 
We would like to inform you that we have prepared a sample based on your requirement. Please find the sample from the below link. 
 
 
We have added our documentation about the LoadMore. Please refer the below link for further information. 
 
 
Please let us know whether the provided solution meets your requirement. 
 
Regards, 
Sangeetha Raju. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon