遍历赋值!

zhanglong_longlong 2010-12-23 11:12:48
后台: public List<string> text = new List<string>();
public List<int> num=new List<int>();

protected void btn_pages_Click(object sender, EventArgs e)
{
com = new SqlCommand("select content,step from zwzt a inner join cvsession b on a.content=b.cvsessions and b.uid=" + cookies, con);
con.Open();
SqlDataReader red = com.ExecuteReader();
while (red.Read())
{
num.Add(Convert.ToInt32(red["step"]));

}

con.Close();
}将num集合值给前台方法 <%#zwzt(num)%></td>



后台zwzt方法:
public string zwzt(List<int> nums)
{
string str="";
int steps=0;
con = new SqlConnection(strConnection);
com = new SqlCommand("select count(step) from zwzt", con);
con.Open();
SqlDataReader red = com.ExecuteReader();
while (red.Read())
{
steps =Convert.ToInt32(red[0]);
}
con.Close();
int tem = 0;
//foreach (int i in nums)
//{
// Response.Write(i);
//}
for (int i = 1; i < steps; i++)
{

if (i < nums[i])
{
str += "<div style='float:left; border:0px red solid; width:16px;height:20px;background:url(../images/arrow_sp.png) -18px -29px'></div>";
if (steps <= 8)
{
str += "<div style='float:left; border:0px red solid; margin-top:4px;padding:0px 28px; height:13px;background:url(../images/arrow_sp.png) 0px -85px'></div>";
}
else if (steps == 9)
{
str += "<div style='float:left; border:0px red solid; margin-top:4px;padding:0px 24px; height:13px;background:url(../images/arrow_sp.png) 0px -85px'></div>";
}
else
str += "<div style='float:left; border:0px red solid; margin-top:4px;padding:0px 21px; height:13px;background:url(../images/arrow_sp.png) 0px -85px'></div>";
}
else if (i == nums[i])
{
str += "<div style='float:left;margin-left:4px; border:0px red solid; width:23px;height:22px;background:url(../images/arrow_sp.png) 0px -54px'></div>";
}
else
{
if (steps <= 8)
{
str += "<div style='float:left;padding:0px 28px;margin-top:2px;height:13px;background:url(../images/arrow_sp.png) 0px -75px repeat-x'></div>";
}
else if (steps == 9)
{
str += "<div style='float:left;padding:0px 24px;margin-top:2px;height:13px;background:url(../images/arrow_sp.png) 0px -75px repeat-x'></div>";
}
else
str += "<div style='float:left;padding:0px 20px;margin-top:2px;height:13px;background:url(../images/arrow_sp.png) 0px -75px repeat-x'></div>";

str += "<div style='float:left; border:0px red solid; width:16px;height:20px;background:url(../images/arrow_sp.png) 3px -29px'></div>";
}
}
return str;
}索引超出范围
...全文
104 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-12-23
  • 打赏
  • 举报
回复
nums.Count与steps 比较
flyerwing 2010-12-23
  • 打赏
  • 举报
回复
foreach不能修改吧.
for

62,074

社区成员

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

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

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

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