0

My listbox doesnt appear data, only the classdata name:

    XDocument doc = XDocument.Parse(XMLfile);
    List<ClassData> data = (from item in doc.Descendants("freq")
         where item.Element("ID").Value > 50
         orderby item.Element("Time").Value
         select new ClassData
         {
              ID= item.Element("ID").Value,
              Name= item.Element("Name").Value,
              Age= item.Element("Age").Value,
              Time= item.Element("Time").Value
          }).ToList<ClassData>();
    lstBox.DataSource = data;
    lstBox.DataBind();

myclassdata:

 public class ClassData
{
    public string ID{ get; set; }
    public string Name{ get; set; }
    public string Age{ get; set; }
    public string Time{ get; set; }
}

I add 4 items in my listbox with same name of my classData Items... my result is: SolutionName.ClassData 32 times (number of results)

2 Answers 2

1

defaultly, the listbox displays the result of ToString() of the items you provided, which is 'SolutionName.ClassData' like you said.
To change that, you need to change the DisplayMember property of the listbox- listBox.DisplayMember = "Name"
for asp.net listbox, it's DataTextField

Sign up to request clarification or add additional context in comments.

2 Comments

sorry, i missed the asp.net bit. i've edited my answer accordingly
OK, but apear only 1 value in the listbox. I need appear all the 4 values like " ID:56 Name:John Age:60 Time:09:00 "
0
 <asp:DataList ID="dataList" runat="server"
        RepeatColumns="1"
        RepeatDirection="Horizontal"
        RepeatLayout="Table">
        <ItemTemplate>
            <table border="1" >
                <tr>
                    <td><asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>' Width="50" /></td>
                    <td><asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>' Width="20" /></td>
                    <td><asp:Label ID="Label3" runat="server" Text='<%# Eval("Age") %>' Width="200" /></td>
                    <td><asp:Label ID="Label4" runat="server" Text='<%# Eval("Time") %>' Width="200" /></td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:DataList>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.