遍历赋值!
后台: 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;
}索引超出范围
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;
}索引超出范围
...全文
相关推荐
bootstrap下拉框动态赋值方法
今天小编就为大家分享一篇bootstrap下拉框动态赋值方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
使用遍历控件或数据表字段的方法实现数据传递
在王晟和韩泽坤主编的《ACCESS》数据库开发经典案例解析中,主、子窗体控件间和窗体控件和数据表字段见数据传递,使用的是一对一赋值的方法,在控件数量比较多的时候,代码写起来很长,也很容易出错。本例使用遍历控件或数据表字段的方法,实现编程代码简化,且降低代码输入错误的几率。
layui 对弹窗 form表单赋值的实现方法
今天小编就为大家分享一篇layui 对弹窗 form表单赋值的实现方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
JS for...in 遍历语句
NULL 博文链接:https://onestopweb.iteye.com/blog/2316198
在页面加载完成后通过jquery给多个span赋值
想在页面加载完成后,有几个地方显示当前时间,所以想通过jquery给多个span赋值,需要的朋友可以参考下


