Asp.net ListBox没有填充

时间:2018-04-25 18:31:56

标签: c# .net amazon-web-services

我一直在使用DynamoDb开发一个asp.net项目,我从Db中获取了该项目并将其变成了一个新的Car对象。当我尝试填充汽车列表框时,我似乎无法获取列表框中的任何对象。 任何帮助,将不胜感激。 继承人我所拥有的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using Amazon.DynamoDBv2.DocumentModel;


public partial class _Default : System.Web.UI.Page
{
    private static AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    private static string tableName = "CarTable";
    private static string sampleCarReg = "05-Rn-1964";
    List<car> cars = new List<car>();

    protected void Page_Load(object sender, EventArgs e)
    {



        Amazon.DynamoDBv2.DocumentModel.Table CarTable =     Amazon.DynamoDBv2.DocumentModel.Table.LoadTable(client, tableName);
        GetItemOperationConfig config = new GetItemOperationConfig
        {
        AttributesToGet = new List<string> { "Reg", "Manufactor", "Year",     "Problems" },
            ConsistentRead = true
        };
        Document doc = CarTable.GetItem(sampleCarReg, config);

        string Reg = doc["Reg"].AsString();
        string Manufactor = doc["Manufactor"].AsString();
        string Year = doc["Year"].AsString();
        string Problems = doc["Problems"].AsString();

       // string Model = doc["Model"].AsString();


        car car1 = new car(Reg, Manufactor, Year, Problems);
        cars.Add(car1);

        lblCar.Text = car1.ToString();
        lbxCars.DataSource = cars;

    }

1 个答案:

答案 0 :(得分:0)

您正在设置ListBox的{​​{1}}媒体资源,但未指定DataSourceDataTextField。您需要设置DataValueField中使用的Car属性。

ListBox

如果您还想选择第一项,请使用// Use what makes sense to you lbxCars.DataSource = cars; lbxCars.DataTextField = "Reg"; lbxCars.DataValueField = "Reg"; lbxCars.DataBind(); 属性。当然,请务必先检查您的车辆清单是否有物品。

SelectedIndex