求助,C#GridView无法显示

西伯利亚大杰瑞 2025-03-03 20:35:13

     后台

           SqlConnection key = new SqlConnection (ConfigurationManager.ConnectionStrings["blogConnectionString"].ConnectionString);
            key.Open ();
            SqlDataAdapter username = new SqlDataAdapter ("select * from UserRegistry where name = '" + "张三" + "'and password = '" + "zhangsan" + "'", key);
            DataSet user = new DataSet ();
            username.Fill (user, "user");
            key.Close ();
            Session["user"] = user;

前台:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="470px">
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:blogConnectionString %>" SelectCommand="SELECT * FROM [post] WHERE ([publisherID] = @publisherID)">
            <SelectParameters>
                <asp:SessionParameter Name="publisherID" SessionField="(DataSet)Sessoin.Tables[&quot;user&quot;].Rows[0][0]" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:blogConnectionString %>" SelectCommand="SELECT * FROM [reply] WHERE ([publisherID] = @publisherID)">
            <SelectParameters>
                <asp:SessionParameter Name="publisherID" SessionField="(DataSet)Session.Tables[&quot;user&quot;].Rows[0][2]" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>

数据源绑定上了,测试查询也能查到,代码也没报错,各位大佬能解释一下么,本人是个菜鸡,虐的轻一点

...全文
210 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

111,076

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧