DataTable动态添加列的问题

wojiushi594 2007-06-18 10:06:08
后台
Person bllPerson = new Person();

DataSet ds_Person = bllPerson.GetCountByAge(queryCode);
DataTable dt_Person = ds_Person.Tables[0];
dt_Person.Columns.Add("Total_Person", typeof(Int32));
DataRow dr_Person = dt_Person.NewRow();
int person_total = 0;
for (int i = 0; i < dt_Person.Rows.Count; i++ )
{
person_total =Int32.Parse( dt_Person.Rows[0]["Count"].ToString());
person_total++;
}
dr_Person[0] = person_total;



dlAgeLevel.DataSource = ds_Person;
dlAgeLevel.DataBind();








前台

<asp:DataList ID="dlFamilyType" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
<ItemTemplate>
共<asp:Label ID="Label13" runat="server" Text='<%# Eval("Total_Person") %>'></asp:Label>户
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Count") %>' CssClass="danganlabel"></asp:Label>户
</ItemTemplate>
</asp:DataList>


运行时问题:
DataBinding:"System.Data.DataRowView"不包含名为“Total_Person”的属性
...全文
694 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wojiushi594 2007-06-18
  • 打赏
  • 举报
回复
我刚运行,点击按钮就报什么未知错误,请刷新后运行是怎么一回事?断点调试也用不了
jimu8130 2007-06-18
  • 打赏
  • 举报
回复
to ChinaZS() :
该在哪里就在哪里,没变化,在你进入社区具体节点后,就可以找到。
wojiushi594 2007-06-18
  • 打赏
  • 举报
回复
应该蛮好找么
ChinaZS 2007-06-18
  • 打赏
  • 举报
回复
我想知道现在的CSDN是在哪提问的?
改的太无耻了~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
原来的 提问 连接不知道都TMD改哪去了?
jimu8130 2007-06-18
  • 打赏
  • 举报
回复
哦明白了,呵呵
没仔细看

其次这部分代码还
DataRow dr_Person = dt_Person.NewRow();
int person_total = 0;
for (int i = 0; i < dt_Person.Rows.Count; i++ )
{
person_total =Int32.Parse( dt_Person.Rows[0]["Count"].ToString());
person_total++;
}
dr_Person[0] = person_total;

dt_Person.Rows.Add(dr_Person); ------------------这句要加在这里!!!!
wojiushi594 2007-06-18
  • 打赏
  • 举报
回复
cpp2017(慕白兄),不好意思代码 太多了看晕了,你说的是的 我正在调试了。
cpp2017 2007-06-18
  • 打赏
  • 举报
回复
慕白的答案怎么让人摸不着头脑? ====> <asp:DataList ID="dlFamilyType" runat="server" dlAgeLevel.DataSource = ds_Person; 这两个不是同一对象 dlFamilyType 与 dlAgeLevel
jimu8130 2007-06-18
  • 打赏
  • 举报
回复
慕白的答案怎么让人摸不着头脑?
这样的加入column了
dtQuestion.Columns.Add(new DataColumn("",int));
xz_xq 2007-06-18
  • 打赏
  • 举报
回复
后台:
Person bllPerson = new Person();

DataSet ds_Person = bllPerson.GetCountByAge(queryCode);
DataTable dt_Person = ds_Person.Tables[0];

dt_Person.Columns.Add(new DataColumn("Total_Person"));

for (int i = 0; i < dt_Person.Rows.Count; i++ )
{
person_total =Int32.Parse( dt_Person.Rows[0]["Count"].ToString());
person_total++;
}

dlAgeLevel.DataSource = ds_Person;
dlAgeLevel.DataBind();
xuan.ye 2007-06-18
  • 打赏
  • 举报
回复
for (int i = 0; i < dt_Person.Rows.Count; i++ )
{
datarow row=new datarow();
person_total =Int32.Parse( dt_Person.Rows[0]["Count"].ToString());
person_total++;
row.add()
}
cpp2017 2007-06-18
  • 打赏
  • 举报
回复
后台绑定的是dlAgeLevel 前台是 dlFamilyType

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧