我写一个类似论坛的一个东西,在标签Labelreplylist中显示记录集中所有信息,比如说:
对一个主题有两个人的回答,我要在页面上全部显示出来,我是像下面这样写的但只显示一条
信息,我在调试发现一个循环会覆盖上一个循环的内容,请大家帮帮忙看怎么写,谢谢!
foreach(DataRow dr in dsreplis.Tables[0].Rows )
{
Labelreplylist.Text=dr["title"].ToString();
Labelreplylist.Text+=" by ";
Labelreplylist.Text+= dr["loginname"].ToString();
Labelreplylist.Text+= " | ";
Labelreplylist.Text+= dr["ip"].ToString();
Labelreplylist.Text+= " | ";
Labelreplylist.Text+= dr["createtime"].ToString();;
Labelreplylist.Text+="<br>";
Labelreplylist.Text+= dr["context"].ToString();
Labelreplylist.Text+="<hr>";
}
对一个主题有两个人的回答,我要在页面上全部显示出来,我是像下面这样写的但只显示一条
信息,我在调试发现一个循环会覆盖上一个循环的内容,请大家帮帮忙看怎么写,谢谢!
foreach(DataRow dr in dsreplis.Tables[0].Rows )
{
Labelreplylist.Text=dr["title"].ToString();
Labelreplylist.Text+=" by ";
Labelreplylist.Text+= dr["loginname"].ToString();
Labelreplylist.Text+= " | ";
Labelreplylist.Text+= dr["ip"].ToString();
Labelreplylist.Text+= " | ";
Labelreplylist.Text+= dr["createtime"].ToString();;
Labelreplylist.Text+="<br>";
Labelreplylist.Text+= dr["context"].ToString();
Labelreplylist.Text+="<hr>";
}
//试试
string temp = "";
foreach(DataRow dr in dsreplis.Tables[0].Rows )
{
temp += dr["title"].ToString();
temp += " by ";
temp += dr["loginname"].ToString();
temp += " ¦ ";
temp += dr["ip"].ToString();
temp += " ¦ ";
temp += dr["createtime"].ToString();;
temp +=" <br>";
temp += dr["context"].ToString();
temp +=" <hr>";
}
Labelreplylist.Text = temp;
string temp = string.Empty;
foreach(DataRow dr in dsreplis.Tables[0].Rows)
{
temp += dr["title"].ToString();
temp += " by ";
temp += dr["loginname"].ToString();
temp += " ¦ ";
temp += dr["ip"].ToString();
temp += " ¦ ";
temp += dr["createtime"].ToString();;
temp +=" <br>";
temp += dr["context"].ToString();
temp + =" <hr>";
}
Labelreplylist.Text = temp;