.建立两个页面A、B
在web.config创建连接
A页面:在GridView里面实现数据库连接并显示出数据,在GridView里面添加超链HyperLinkField,并使之连接到B页面。用于将GridView的一行数据的信息显示到B页面中。(注意:在HyperLinkField属性的DataNavigateUrlFields 设置你的主键ID,比如DataNavigateUrlFields="StuId"),
B页面:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class MemberManage_EditGInfo : System.Web.UI.Page
{
SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sqlconn.Open();//打开数据库连接
string strid = Page.Request.QueryString["GoodsID"];//接收页面传值
string sqlstr = "select * from tbPicture where PicId='" + strid + "'";//创建查询语句
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlconn);
DataSet myds = new DataSet();
myda.Fill(myds, "tbPicture");
DataRowView mydrv = myds.Tables["tbPicture"].DefaultView[0];//创建表视图DataRowView
txtGID.Text = Convert.ToString(mydrv.Row["PicId"]);
txtGName.Text = Convert.ToString(mydrv.Row["PicName"]);
txtGType.Text = Convert.ToString(mydrv.Row["PicType"]);
txtGStore.Text = Convert.ToString(mydrv.Row["GoodsStock"]);
txtGPrice.Text = Convert.ToString(mydrv.Row["SellNumber"]);
txtGIntro.Text = Convert.ToString(mydrv.Row["PicName"]) + "…";
iGPhoto.ImageUrl = Convert.ToString(mydrv.Row["PicPath"]);
}
}
}