Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am binding data to listbox in wp7

here is the code
XML
<ListBox x:Name="list_budget" Width="440">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Name="txtname" Text="{Binding category}"></TextBlock>

                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>


//class function
C#
 public List<string> jinal;

        public void  budgetcategorywise()
        {

            var q = from shoppingItem p in db.Item1
                    group p by new { p.category_name } into g
                    select new { category = g.Key, total = g.Sum(p => p.total_amt) }.ToString();

          jinal = q.ToList();
    }


//coding

 list_budget.ItemsSource = App.Viewmod.jinal;


now,the error is query is ok result is perfact but i am not able to bind the data to listbox.
Posted
Updated 2-Jun-12 1:56am
v3

1 solution

Hi.
First of all add in ListBox definition of ItemSource property.See below:

XML
<ListBox x:Name="list_budget" ItemSource="{Binding}" Width="440">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Name="txtname" Text="{Binding category}"></TextBlock>

                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>


And alos why you declared variable jinal as:
C#
List<string></string>

????

I suppose, that it must be
C#
List<resultset> jinal</resultset>

, where ResulttSet could be represent as follow:

C#
public class ResulSet
{
public string Name {get; set;}
public int Total {get; set;}
}


Also, it would be more prefarable to use ObservableCollection instead of List!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900