protected void Page_Load(object sender, EventArgs e)
{
strSql = "SELECT * from [class] order by aid desc";
SqlConnection objConnection = new SqlConnection(ConfigurationSettings.AppSettings["dns"]);
objConnection.Open();
SqlCommand cmd = new SqlCommand(strSql, objConnection);
SqlDataReader dr = cmd.ExecuteReader();
int i = 1;
while (dr.Read())
{
if (i == 1)
{
aname += "" + dr["aname"] + "";
}
else
{
aname += "," + dr["aname"] + "";
}
i++;
}
dr.Close();
objConnection.Close();
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
string content= Request.Params["content"]; string[] conArr = Regex.Split(aname, ",");
int pageCount = conArr.Length; for (int p = 0; p < pageCount; p++)
{
aname = conArr[p]; content= content.ToString().Replace(aname, " <a href=class" + aid+ ".html>" + aname+ " </a>");
}
lastcontent = content;
Response.Write(lastcontent);
} 我用上面的代码实现了这么一个功能
牵系到数据库中有一个表class,结构如下aid aname
1 苹果
2 香蕉
3 毛桃
.
.
. 我想实现的是,自动匹配文章中的内容,就是从表class匹配,给相同的内容加上链接举个例子,我输入的文字是我有一个苹果,但我更喜欢吃香蕉,但被小王吃了,最后他给了我一个毛桃,我很不开心,大声喊道,我要吃苹果。匹配后,得到的应该是我有一个 <a href="class1.html">苹果 </a>,但我更喜欢吃 <a href="class2.html">香蕉 </a>,但被小王吃了,最后他给了我一个 <a href="class3.html">毛桃 </a>,我很不开心,大声喊道,我要吃 <a href="class1.html">苹果 </a>。
但上面的程序提示,出错,当前上下文中不存在名称“aid”,请问这里怎么获取和aname对应起来的aid,让他们显示正确呢?
{
strSql = "SELECT * from [class] order by aid desc";
SqlConnection objConnection = new SqlConnection(ConfigurationSettings.AppSettings["dns"]);
objConnection.Open();
SqlCommand cmd = new SqlCommand(strSql, objConnection);
SqlDataReader dr = cmd.ExecuteReader();
int i = 1;
while (dr.Read())
{
if (i == 1)
{
aname += "" + dr["aname"] + "";
}
else
{
aname += "," + dr["aname"] + "";
}
i++;
}
dr.Close();
objConnection.Close();
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
string content= Request.Params["content"]; string[] conArr = Regex.Split(aname, ",");
int pageCount = conArr.Length; for (int p = 0; p < pageCount; p++)
{
aname = conArr[p]; content= content.ToString().Replace(aname, " <a href=class" + aid+ ".html>" + aname+ " </a>");
}
lastcontent = content;
Response.Write(lastcontent);
} 我用上面的代码实现了这么一个功能
牵系到数据库中有一个表class,结构如下aid aname
1 苹果
2 香蕉
3 毛桃
.
.
. 我想实现的是,自动匹配文章中的内容,就是从表class匹配,给相同的内容加上链接举个例子,我输入的文字是我有一个苹果,但我更喜欢吃香蕉,但被小王吃了,最后他给了我一个毛桃,我很不开心,大声喊道,我要吃苹果。匹配后,得到的应该是我有一个 <a href="class1.html">苹果 </a>,但我更喜欢吃 <a href="class2.html">香蕉 </a>,但被小王吃了,最后他给了我一个 <a href="class3.html">毛桃 </a>,我很不开心,大声喊道,我要吃 <a href="class1.html">苹果 </a>。
但上面的程序提示,出错,当前上下文中不存在名称“aid”,请问这里怎么获取和aname对应起来的aid,让他们显示正确呢?
.aspx页面代码是
<textarea id="summary" runat="server"></textarea><asp:Button ID="BtnSubmit" runat="server" Text="提交" OnClick="BtnSubmit_Click" />
就这样提交过来的
03加什么呢?
string aname=string.Empty;
string anameNew =string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
strSql = "SELECT * from [class] order by aid desc";
SqlConnection objConnection = new SqlConnection(ConfigurationSettings.AppSettings["dns"]);
objConnection.Open();
SqlCommand cmd = new SqlCommand(strSql, objConnection);
SqlDataReader dr = cmd.ExecuteReader();
int i = 1;
while (dr.Read())
{
if (i == 1)
{
aname=aname+"+dr["aname"] +"-"dr["aid"] +";
}
else
{
aname=aname+"," +"+dr["aname"] +"-"dr["aid"] +"; }
i++;
}
dr.Close();
objConnection.Close();
} protected void BtnSubmit_Click(object sender, EventArgs e)
{
string content= Request.Params["content"]; string[] conArr = Regex.Split(aname, ","); int = conArr.Length;
for(int i=0;i<pageCount ;i++)
{
anameNew = conArr[i];
string[] conArrNew =Regex.Split(aname, "-");
content= <a href=class" + conArrNew [0].Tostring()+ ".html>" + conArrNew [1].Tostring()+ " </a>"); }
lastcontent = content;
Response.Write(lastcontent);
}