我正在尝试从listbox
获取一个项目并将其作为car
项目。
我想取tempcar
,取出它的值并将它们添加到会话状态值,我可以在其他页面上编辑值。
目前我正在使用来自应用程序的这个回收代码,但由于以下问题,它似乎不适用于webforms 无法将类型系统web ui webcontrols listitem转换为汽车
if (lbxCars.SelectedItem != null)
{
car tempCar = lbxCars.SelectedItem as car;
}
任何帮助都会受到广泛赞赏。另外,我理解我正在做的是笨重,但这是为了展示功能。
谢谢
public partial class _Default : System.Web.UI.Page
{
private static AmazonDynamoDBClient client = new AmazonDynamoDBClient();
private static string tableName = "CarTable";
private static string car_1 = "05-Rn-1964";
private static string car_2 = "05-Rn-1965";
private static string car_3 = "05-Rn-1966";
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 doc1 = CarTable.GetItem(car_1, config);
Document doc2 = CarTable.GetItem(car_2, config);
Document doc3 = CarTable.GetItem(car_3, config);
string Reg1 = doc1["Reg"].AsString();
string Manufactor1 = doc1["Manufactor"].AsString();
string Year1 = doc1["Year"].AsString();
string Problems1 = doc1["Problems"].AsString();
string Reg2 = doc2["Reg"].AsString();
string Manufactor2 = doc2["Manufactor"].AsString();
string Year2 = doc2["Year"].AsString();
string Problems2 = doc2["Problems"].AsString();
string Reg3 = doc3["Reg"].AsString();
string Manufactor3 = doc3["Manufactor"].AsString();
string Year3 = doc3["Year"].AsString();
string Problems3 = doc3["Problems"].AsString();
car car1 = new car(Reg1, Manufactor1, Year1, Problems1);
car car2 = new car(Reg2, Manufactor2, Year2, Problems2);
car car3 = new car(Reg3, Manufactor3, Year3, Problems3);
cars.Add(car1);
cars.Add(car2);
cars.Add(car3);
lbxCars.DataSource = cars;
lbxCars.DataBind();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Server.Transfer("Default.aspx", true);
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Server.Transfer("EditCar.aspx", true);
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Server.Transfer("NewCar.aspx", true);
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
Server.Transfer("ViewDataBase.aspx", true);
}
protected void Button2_Click(object sender, EventArgs e)
{
Server.Transfer("EditCar.aspx", true);
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbxCars.SelectedItem != null)
{
//car tempCar = lbxCars.SelectedItem as car;
}
}
}
答案 0 :(得分:0)
您可以尝试这样的操作,其中ID是您用于列表框中SelectedValue的属性。
override void viewAppearing