我點擊API並將返回的解析數據存儲到List
。目前,我正在顯示ListView
中的數據。 我無法在GridView
中顯示相同的列表。任何人都可以指導我如何做到這一點?如何將列表<string>綁定到ASP.NET中的GridView?
這是我的aspx.cs代碼:
protected void Page_Load(object sender, EventArgs e)
{
ComodityList obj_comodity_in = (ComodityList)Session["comodity_list"];
Label1.Text = obj_comodity_in.status_code;
Label2.Text = obj_comodity_in.count.ToString();
//ComodityList obj_comodity_in = (ComodityList)Session["comodity_list"];
List<String> commodity_names = null;
getComodityNames(out commodity_names, obj_comodity_in);
ListView1.DataSource = commodity_names;
ListView1.DataBind();
}
private void getComodityNames(out List<String> commodity_names, ComodityList cl)
{
commodity_names = new List<string>();
foreach (Commodity c in cl.data)
{
commodity_names.Add(c.commodity);
commodity_names.Add(c.state);
commodity_names.Add(c.market);
commodity_names.Add(c.Maximum_Price.ToString());
commodity_names.Add(c.Minimum_Price.ToString());
commodity_names.Add(c.Modal_Price.ToString());
commodity_names.Add(c.origin);
commodity_names.Add(c.unit);
commodity_names.Add(c.variety);
}
}
好了,一維數組一格?這有意義嗎? – 2013-03-17 07:20:48
沒有意義...使用中繼器控制? – CarneyCode 2013-03-17 07:29:36