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. Image for the cookie policy date

Listview not binding...showing empty list

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>



7 Replies

SR Sangeetha Raju Syncfusion Team 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. 



VS Vijil Stephen 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


SR Sangeetha Raju Syncfusion Team 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. 



VS Vijil Stephen September 24, 2019 05:57 AM UTC

Hi,

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

Thanks for the support.


SR Sangeetha Raju Syncfusion Team 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. 



VS Vijil Stephen 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.


SR Sangeetha Raju Syncfusion Team 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. 


Loader.
Live Chat Icon For mobile
Up arrow icon