How to get single value of List<object>

后端 未结 2 361
悲哀的现实
悲哀的现实 2021-01-18 10:29

I\'m a new to ASPX, hope you dont mind if my problem is so simple with somebody.

I use a List selectedValues;

selectedValu         


        
      
      
      
2条回答
  •  日久生厌
    2021-01-18 11:04

    You can access the fields by indexing the object array:

    foreach (object[] item in selectedValues)
    {
      idTextBox.Text = item[0];
      titleTextBox.Text = item[1];
      contentTextBox.Text = item[2];
    }
    

    That said, you'd be better off storing the fields in a small class of your own if the number of items is not dynamic:

    public class MyObject
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }
    }
    

    Then you can do:

    foreach (MyObject item in selectedValues)
    {
      idTextBox.Text = item.Id;
      titleTextBox.Text = item.Title;
      contentTextBox.Text = item.Content;
    }
    

提交回复
热议问题