selladurai
selladurai

Reputation: 6789

How to bind the values web service in to grid in windows phone 7?

I'm working in window phone. I have to bind data in to grid in windows phone.alt text

alt text

I got results from web service such as name , address, id, category. I need When I click the name, it displays the all details. So, how can I do to display those details?

Upvotes: 0

Views: 1624

Answers (2)

Matt Lacey
Matt Lacey

Reputation: 65586

As Mike says, look at the code created as part of a new DataBound application.

Also, rather than displaying data in a grid, it's probably better to display data vertically in a column:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <StackPanel>
        <TextBlock Text="Name" Style="{StaticResource PhoneTextLargeStyle}" />
        <TextBlock Text="{}Binding Name}" Margin="20,0,0,0" />
        <TextBlock Text="ID" Style="{StaticResource PhoneTextLargeStyle}" />
        <TextBlock Text="{Binding ID}" Margin="20,0,0,0" />
        <TextBlock Text="City" Style="{StaticResource PhoneTextLargeStyle}" />
        <TextBlock Text="{Binding City}" Margin="20,0,0,0" />
        <TextBlock Text="Category" Style="{StaticResource PhoneTextLargeStyle}" />
        <TextBlock Text="{Binding Category}" Margin="20,0,0,0" />
        <TextBlock Text="Others" Style="{StaticResource PhoneTextLargeStyle}" />
        <TextBlock Text="{Binding Others}" Margin="20,0,0,0" TextWrapping="Wrap" />
    </StackPanel>
</Grid>

And as a quick way to see what this might look like when populated:

public partial class MainPage : PhoneApplicationPage
{
    public MainPage()
    {
        InitializeComponent();

        Loaded += MainPage_Loaded;
    }

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        // This would really be the data returned from the web service
        var sampleData = new WsData
                             {
                                 Name = "Girilas & Gandhi Nagar",
                                 ID = "842",
                                 City = "Bangalore",
                                 Category = "Shopping Mall",
                                 Others = "AC Types:  central\n AC, Split AC Windows\nACWhirlpool:\nMicrowave Oven ..."
                             };

        this.DataContext = sampleData;
    }
}

public class WsData
{
    public string Name { get; set; }
    public string ID { get; set; }
    public string City { get; set; }
    public string Category { get; set; }
    public string Others { get; set; }
}

Upvotes: 2

Mick N
Mick N

Reputation: 14882

You might like to have a look at making a project using the Databound Project template, as it produces a result very similar to what you describe that you can use as a starting point.

Upvotes: 1

Related Questions