gridview 传值在另一个页面获取时显示服务器错误
页面一前台后台页面二前台<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"GridL...
页面一前台
后台
页面二前台
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
GridLines="None" ShowHeader="False"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a id="link3" href="Details?newsid=<%#Eval("newsid")%>" > <%#Eval("newstitle")%> </a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台
protected void Page_Load(object sender, EventArgs e)
{
string dsn = System.Configuration.ConfigurationManager.ConnectionStrings["dsn"].ToString();
SqlConnection con = new SqlConnection(dsn);
string id;
if (Request.QueryString["newstype"]== null)
{
id = "0";
}
else id = Request.QueryString["newstype"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM news WHERE newstype=" + id + "", con);
SqlDataReader sdr = cmd.ExecuteReader();
this.GridView1.DataSource = sdr;
this.GridView1.DataBind();
sdr.Close();
cmd.Dispose();
con.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
} 展开
后台
页面二前台
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
GridLines="None" ShowHeader="False"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a id="link3" href="Details?newsid=<%#Eval("newsid")%>" > <%#Eval("newstitle")%> </a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台
protected void Page_Load(object sender, EventArgs e)
{
string dsn = System.Configuration.ConfigurationManager.ConnectionStrings["dsn"].ToString();
SqlConnection con = new SqlConnection(dsn);
string id;
if (Request.QueryString["newstype"]== null)
{
id = "0";
}
else id = Request.QueryString["newstype"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM news WHERE newstype=" + id + "", con);
SqlDataReader sdr = cmd.ExecuteReader();
this.GridView1.DataSource = sdr;
this.GridView1.DataBind();
sdr.Close();
cmd.Dispose();
con.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
} 展开
3个回答
展开全部
看看跳转之后的浏览器地址url是否正确,应该是url路径不对。
追问
路径就是Details.aspx?newstype={0}呀。。。
追答
是你路径错了,你截图看看你跳转之后错误的页面Details.aspx的url地址,然后看看正常访问Details.aspx?newstype=1的url地址就知道了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dsadasdsadasd
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询