【发布时间】:2014-08-01 06:04:25
【问题描述】:
我在网格中绑定数据时遇到了一些困难。
我的数据:
时间 1 2
00:00 , ,
00.30 , ,
01:00 , ,
01:30 , ,
02:00 , ,
02:30 , ,
..等等
我的代码:
public partial class data : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
data1();
}
public void data1()
{
List<MyKVP> obj1 = new List<MyKVP>();
List<string> str = new List<string>() { "Time", "1", "2" };
List<string> str1 = new List<string>() { "00:00", "00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00" };
for (int count = 0; count < str1.Count; count++)
{
MyKVP obj = new MyKVP();
if (count == 0)
{
obj.Key="0";
for (int i = 0; i < str.Count; i++)
{
Value o = new Value();
o.name = str[i];
obj.value.Add(o);
}
}
else
{
obj.Key = Convert.ToString(count);
Value o = new Value();
o.name = ":";
obj.value.Add(o);
}
obj1.Add(obj);
}
GridView1.DataSource = obj1;
GridView1.DataBind();
}
}
public class MyKVP
{
public MyKVP()
{
value = new List<Value>();
}
public string Key { get; set; }
public List<Value> value { get; set; }
}
public class Value
{
public string name { get; set; }
}
我只得到网格中的键,而不是列表中的值列表。
我的圣诞节
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</form>
【问题讨论】:
-
你有什么问题?您是否遇到某种错误?
-
我没有收到任何错误,它只显示键而不是列表中的值
-
对,但你必须告诉我们。
-
您还需要向我们展示您的
XAML代码。 -
好的。我会在问题中更新