0

I'm trying to load specific data from my api into datagrid. I make requests for specific Id, and the results should be appear in data grid

Here's my code behind :

private async void btnSearch_Click(object sender, RoutedEventArgs e)
{
      using (WebClient client = new WebClient())
      {
          try
          {
              string url = string.Format("https://localhost:44324/api/Channels/{0}", idtxt.Text);
              var json = client.DownloadString(url);

              Channelindex info = JsonConvert.DeserializeObject<Channelindex>(json);

           

              txtName.Text = info.name;
              txturl.Text=info.url;
              Usergrid. Itemsource=info.url;
                

              MessageBox.Show("User Found : " + info.name + " " + info.url);

          }
          catch (Exception ex)
          {
               MessageBox.Show("Unable To Locate ID: " + ex.Message, "Exception Sample", MessageBoxButton.OK, MessageBoxImage.Error);

          }
    }
}

But my datagrid fails. I'd appreciate if you help me Thanks.

Meysam Asadi
  • 6,438
  • 3
  • 7
  • 17

1 Answers1

0

As your code suggest Channelindex info is an object with a property of url being a string. This is not a valid ItemsSource (not Itemsource). It should be a list of items.

Without more code it's hard to tell, but I would suggest

Usergrid.ItemsSource = new string[] { info.url };

or

Usergrid.ItemsSource = new[] { info };

and then specify a column definition to pick url. See https://stackoverflow.com/a/10761291/394076 for more info

Martin
  • 1,028
  • 17
  • 23