OleDbDataReader Txtsetting = Class.ExecuteRed(strSql);
int i = 0;
while (Txtsetting.Read())
{
txtTitle = txtTitle + i++ + "<li class='active' onclick='nTabs(this,0);'>Introduction</li>"; //标题
}
Txtsetting.Close();
Txtsetting.Dispose();
Txtsetting = null;
我查出3条数据显示结果为0
Introduction 1
Introduction 2
Introduction为什么这样?没见过啊,我想要的结果是:Introduction 0
Introduction 1
Introduction 2望大家指点,谢谢
{
i++;
txtTitle = txtTitle + i + "<li class='active' onclick='nTabs(this,0);'>Introduction</li>"; //标题
}试一试
这个东西一开始为空吧...
int i = 0;
txtTitle=string.Empty;
while (Txtsetting.Read())
{
txtTitle = txtTitle + "<li class='active' onclick='nTabs(this,0);'>Introduction</li>"+i;
i++; //标题
}
Txtsetting.Close();
Txtsetting.Dispose();
Txtsetting = null;
int i = 0;
txtTitle=string.Empty;
while (Txtsetting.Read())
{
txtTitle += "<li class='active' onclick='nTabs(this,0);'>Introduction</li>"; //标题
txtTitle+=i.ToString();
i++;
}
Txtsetting.Close();
Txtsetting.Dispose();
Txtsetting = null;
就不行了呢?
i++;
Introduction 0
Introduction 1
Introduction 2就应该 "<li>Introduction </li>" + i++ 为一行
写成 i++ +"<li>Introduction </li>"了
i是int型,tostring()变成字符串,才能和字符串拼接 (int.toString() + string)否则,.net会尝试把后边的string型转化为int…… 然后转化不能,报错。