我现在在做一个网站的后台,
在后台页面已经获取到了新闻标题的列表页面 在新闻标题后面有个 编辑新闻 和删除新闻的链接 ;
分别是链接到一个新闻编辑页面和一个新闻删除的页面;
我现在想在新闻列表页面点击 编辑新闻 的时候跳到新闻编辑页面,并且在新闻编辑页面对应的位置(textbox)里面显示相应的数据;
当我编辑完内容点击提交修改的按钮后,在sql语句中怎么获取到这条新闻的id值?编辑页面后台代码大概是这样的:用了个sqlhelper文件using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Xml.Linq;public partial class YXhtgl_ServicesEdit : System.Web.UI.Page
{
SqlHelper help = new SqlHelper();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
serviceselect(Request["sid"]);
}
} //将读取的数据绑定到编辑页面相应的位置
public void serviceselect(string sid)
{
string sqlservices = "select * from YXServices where SID=" + sid;
SqlDataReader sdr = help.RunDataReader(sqlservices);
if (sdr.Read())
{
this.tbname.Text = sdr["STitle"].ToString();
this.FCKeditor1.Value = sdr["SContent"].ToString();
}
sdr.Close();
} //点击提交按钮时的操作
protected void btsub_Click(object sender, EventArgs e)
{
string strTitle = this.tbname.Text;
string strContent = this.FCKeditor1.Value;
string strImg = this.FileUpload1.FileName.ToString();
if (strImg == "" || strImg == null)
{
string sqlupdate1 = "update YXServices set STitle= '" + strTitle + "' , SContent= '" + strContent + "' where SID=" + ???;
int i = help.ExecuteNonQuery(sqlupdate1);
if (i > 0)
{
Response.Write("<script>alert('提交成功!')</script>");
}
else
{
Response.Write("<script>alert('提交失败!')</script>");
}
}
else
{
string sqlupdate2 = "update YXServices set STitle= '" + strTitle + "' , SContent= '" + strContent + "' , SImage= '" + strImg + "' where SID=" + ???;
int i1 = help.ExecuteNonQuery(sqlupdate2);
if (i1 > 0)
{
Response.Write("<script>alert('提交成功!')</script>");
}
else
{
Response.Write("<script>alert('提交失败!')</script>");
}
}
}
}
还请各位高手帮帮忙!
在后台页面已经获取到了新闻标题的列表页面 在新闻标题后面有个 编辑新闻 和删除新闻的链接 ;
分别是链接到一个新闻编辑页面和一个新闻删除的页面;
我现在想在新闻列表页面点击 编辑新闻 的时候跳到新闻编辑页面,并且在新闻编辑页面对应的位置(textbox)里面显示相应的数据;
当我编辑完内容点击提交修改的按钮后,在sql语句中怎么获取到这条新闻的id值?编辑页面后台代码大概是这样的:用了个sqlhelper文件using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Xml.Linq;public partial class YXhtgl_ServicesEdit : System.Web.UI.Page
{
SqlHelper help = new SqlHelper();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
serviceselect(Request["sid"]);
}
} //将读取的数据绑定到编辑页面相应的位置
public void serviceselect(string sid)
{
string sqlservices = "select * from YXServices where SID=" + sid;
SqlDataReader sdr = help.RunDataReader(sqlservices);
if (sdr.Read())
{
this.tbname.Text = sdr["STitle"].ToString();
this.FCKeditor1.Value = sdr["SContent"].ToString();
}
sdr.Close();
} //点击提交按钮时的操作
protected void btsub_Click(object sender, EventArgs e)
{
string strTitle = this.tbname.Text;
string strContent = this.FCKeditor1.Value;
string strImg = this.FileUpload1.FileName.ToString();
if (strImg == "" || strImg == null)
{
string sqlupdate1 = "update YXServices set STitle= '" + strTitle + "' , SContent= '" + strContent + "' where SID=" + ???;
int i = help.ExecuteNonQuery(sqlupdate1);
if (i > 0)
{
Response.Write("<script>alert('提交成功!')</script>");
}
else
{
Response.Write("<script>alert('提交失败!')</script>");
}
}
else
{
string sqlupdate2 = "update YXServices set STitle= '" + strTitle + "' , SContent= '" + strContent + "' , SImage= '" + strImg + "' where SID=" + ???;
int i1 = help.ExecuteNonQuery(sqlupdate2);
if (i1 > 0)
{
Response.Write("<script>alert('提交成功!')</script>");
}
else
{
Response.Write("<script>alert('提交失败!')</script>");
}
}
}
}
还请各位高手帮帮忙!
解决方案 »
- 请教:关于GridView控件自动生成select语句的问题
- 怎么判断同一个IP地址24小时只能注册一次?
- 一个简单的问题()
- 请改成c#的
- ASP.NET中的登陆控件,怎么连接到自己创建的数据库
- 怪事怪事!为什么用localhost访问本地网站登录不了,而用IP地址192.168.1.*和127.0.0.1却可以?
- URL映射???
- 急!!!Sql2005问题
- 有关:SELECT count(*) from XXX的问题
- 两台机子仅有一点不同,一个装了活动目录,另外一个没有!,装了活动目录怎么也无法运行asp.net,怎么回事?
- 关于域摘要式身份验证的问题
- 求Lucene.net高人解决下索引文件更新问题
在编辑页中根据id找到相应的新闻内容
那样就不会出现找不到id的问题了
O(∩_∩)O~
string sid = Request.QueryString["sid"];
那么,SID就是你要的参数
在编辑页面你可以通过Request.QueryString["SID"]来获取参数的值30,
然后构造Select语句从数据库中查询出这条数据填充到DataTable
再给表单中的对应项赋值
编辑完成后提交,构造Update语句
你可以单独定义一个属性来对SID的值进行安全验证
如: ViewState["uid"] = uid; 更新后再次取出
或者:
string sqlupdate1 = "update YXServices set STitle= '" + strTitle + "' , SContent= '" + strContent + "' where SID="+uid+" ; select @@identity;" ;
更新的sql后面返回回来接收该id, select @@identity
public string XTBH
{
get{return ViewState["xtbh"].ToString();}
set {ViewState["xtbh"]=value;}
}
string sqlupdate2 = "update YXServices set STitle= '" + strTitle + "' , SContent= '" + strContent + "' , SImage= '" + strImg + "' where SID="+XTBH;
最简单的!
然后页面跳转 用 url.aspx?id=xxx
在接受页面的page_load里request.QueryString[id]
继续用sqlhelper查询当前id那条纪录,并且显示