本人是初学者,现在编写一个数据库查询的页面。先说明如下:
1、有两个页面a.aspx和b.aspx;
2、a.aspx和b.aspx中各放有一个GridView控件;
3、a.aspx页面通过GridView控件中的HyperLink提交按钮进行传值给b.aspx页面;语句如下:
……
<asp:TemplateField HeaderText="浏览">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" OnClientClick="<%# "window.open('Default2.aspx?id_1=" + Eval("DP_001") + "&id_2=" + Eval("DP_002") + "')" %>" runat="server">浏览</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
……
4、b.aspx页面中的GridView控件将根据传值参数id_2进行数据库条件查询。语句如下:
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string text_1 = Request.QueryString["id_1"];
string text_2 = Request.QueryString["id_2"];
TextBox1.Text=text_1;
TextBox2.Text=text_2;
}
protected void Button1_Click(object sender, EventArgs e)
{
//实例化SqlConnection对象
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = "server=HEWUHEN;uid=sa;pwd=;database=db_Student"; //定义SQL语句
string SqlStr_1 = "select * from tb_Drawing_ML where DML_001='TextBox2.Text'";
//实例化SqlDataAdapter对象
SqlDataAdapter da_1 = new SqlDataAdapter(SqlStr_1, sqlCon);
//实例化数据集DataSet
DataSet ds_1 = new DataSet();
da_1.Fill(ds_1, "tb_Drawing_ML");
//绑定DataList控件
GridView1.DataSource = ds_1;//设置数据源,用于填充控件中的项的值列表
GridView1.DataBind();//将控件及其所有子控件绑定到指定的数据源
da_1.Dispose(); }
}请问各位大侠,以上程序中什么地方错了。我调试了几次都过不去。谢谢!
另外,有什么好的方法,望各位指教!
1、有两个页面a.aspx和b.aspx;
2、a.aspx和b.aspx中各放有一个GridView控件;
3、a.aspx页面通过GridView控件中的HyperLink提交按钮进行传值给b.aspx页面;语句如下:
……
<asp:TemplateField HeaderText="浏览">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" OnClientClick="<%# "window.open('Default2.aspx?id_1=" + Eval("DP_001") + "&id_2=" + Eval("DP_002") + "')" %>" runat="server">浏览</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
……
4、b.aspx页面中的GridView控件将根据传值参数id_2进行数据库条件查询。语句如下:
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string text_1 = Request.QueryString["id_1"];
string text_2 = Request.QueryString["id_2"];
TextBox1.Text=text_1;
TextBox2.Text=text_2;
}
protected void Button1_Click(object sender, EventArgs e)
{
//实例化SqlConnection对象
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = "server=HEWUHEN;uid=sa;pwd=;database=db_Student"; //定义SQL语句
string SqlStr_1 = "select * from tb_Drawing_ML where DML_001='TextBox2.Text'";
//实例化SqlDataAdapter对象
SqlDataAdapter da_1 = new SqlDataAdapter(SqlStr_1, sqlCon);
//实例化数据集DataSet
DataSet ds_1 = new DataSet();
da_1.Fill(ds_1, "tb_Drawing_ML");
//绑定DataList控件
GridView1.DataSource = ds_1;//设置数据源,用于填充控件中的项的值列表
GridView1.DataBind();//将控件及其所有子控件绑定到指定的数据源
da_1.Dispose(); }
}请问各位大侠,以上程序中什么地方错了。我调试了几次都过不去。谢谢!
另外,有什么好的方法,望各位指教!
解决方案 »
- 下面这句话是什么意思啊
- 未能加载文件或程序集“System.ServiceModel.DomainServices.Server
- 求助关于简单的加密解密--System.Security.Cryptography.DESCryptoServiceProvider
- 流量代码中的UrlReferrer问题,求教,在线等!
- 一些设计上的问题....澳大利亚那边的......嘻嘻
- 如何实现镱像及DNS智能解析。
- 使用SqlHelper.ExecuteDataset查询存储过程,返回参数的问题
- 第一次使用2003 SERVER,遇到权限的问题,高手请来~~
- 问一下消息队列能不能用于远程接发呀
- 初学问题,LABEL控件没有CLICK事件
- 问问的问一下AspNetMVC1 Microsoft .NET Pet Shop 4.0 这都是什么?
- 在asp:GridView 为什么我要连点两次编辑才能切换到编辑模式?
<asp:TemplateField HeaderText="浏览">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandName="open" runat="server">浏览 </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>后台gridview rowcommand
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName == "open")
{
//find id1 id2 here
string id_1 = "";
string id_2 = "";
string script = string.Format("window.open('Default2.aspx?id_1={0}&id_2={1}');",id_1, id_2 );
ClientScript.RegisterStartupScript(GetType(), "open", script, true);
}
}
<ItemTemplate>
<a href='<%# "javascript:window.open(\"a.aspx?ID=" + Eval("ID")+ "\",null,\"width=300,height=200\");void 0;" %>'><%# Eval("Name")%></a>
</ItemTemplate>
我在其中增加了一个传值数据的判断if (TextBox2.Text != null){},代码如下:
if (!IsPostBack)
{
//实例化SqlConnection对象
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = "server=HEWUHEN;uid=sa;pwd=;database=db_Student"; if (TextBox2.Text != null)
{ string sqlStr = "Server=HEWUHEN;DataBase=db_Student;User id=sa;Pwd=";
SqlConnection con = new SqlConnection(sqlStr);
con.Open();
string cmdStr = "select * from tb_Drawing_P where DP_002='" + TextBox2.Text + "'";
SqlCommand cmd = new SqlCommand(cmdStr, con);
SqlDataReader dr = cmd.ExecuteReader();
//循环将数据添加到列表控件中
if (dr.Read())
{
TextBox3.Text=dr.GetString(dr.GetOrdinal("DP_003"));
TextBox4.Text = dr.GetString(dr.GetOrdinal("DP_004"));
TextBox5.Text = dr.GetString(dr.GetOrdinal("DP_005"));
TextBox6.Text = dr.GetString(dr.GetOrdinal("DP_006"));
TextBox7.Text = dr.GetString(dr.GetOrdinal("DP_007"));
TextBox8.Text = dr.GetString(dr.GetOrdinal("DP_008"));
TextBox9.Text = dr.GetString(dr.GetOrdinal("DP_009"));
TextBox10.Text = dr.GetString(dr.GetOrdinal("DP_010"));
TextBox11.Text = dr.GetString(dr.GetOrdinal("DP_011"));
TextBox12.Text = dr.GetString(dr.GetOrdinal("DP_012"));
TextBox13.Text = dr.GetString(dr.GetOrdinal("DP_013"));
}
//关闭数据库
con.Close();
//定义SQL语句
string SqlStr_1 = "select * from tb_Drawing_ML where DML_001='" + TextBox2.Text + "' ORDER BY DML_002 ASC";
//实例化SqlDataAdapter对象
SqlDataAdapter da_1 = new SqlDataAdapter(SqlStr_1, sqlCon);
//实例化数据集DataSet
DataSet ds_1 = new DataSet();
da_1.Fill(ds_1, "tb_Drawing_ML");
//绑定DataList控件
GridView1.DataSource = ds_1;//设置数据源,用于填充控件中的项的值列表
GridView1.DataBind();//将控件及其所有子控件绑定到指定的数据源
da_1.Dispose();
sqlCon.Close();
}
}