日期:2014-05-17  浏览次数:20520 次

为什么GridView显示不出来?求指导

public partial class friendlist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!CheckUser())
            Response.Redirect("Login.aspx");
        if (!this.IsPostBack)
            InitData();
    }
    private bool CheckUser()
    {
        if (Session["login_name"] == null)
        {
            Response.Write("<Script Language=JavaScript>alert('请登录!');</Script>");
            return false;
        }
        return true;
    }
    private void InitData()
    {
        System.Data.SqlClient.SqlConnection conn = new SqlConnection();
        conn.ConnectionString =
           ConfigurationManager.ConnectionStrings["MyBBSConnectionString"].ConnectionString;
        SqlCommand cmd1 = new SqlCommand();
        cmd1.Connection = conn;
        cmd1.CommandText = "SELECT* FROM[Friend] where UserName=@UserName";
        cmd1.CommandType = CommandType.Text;
        SqlParameter para0 = new SqlParameter("@UserName", SqlDbType.VarChar, 50);
        para0.Value = Session["login_name"].ToString();
        cmd1.Parameters.Add(para0);
        conn.Open();
        cmd1.ExecuteNonQuery();
        SqlDataReader dr1 = cmd1.ExecuteReader();

        GV.DataSource = dr1;
        GV.DataBind();
        LabelPages.Text = "查询结果(第" + (GV.PageIndex + 1).ToString() + "页 共" + GV.PageCount.ToString() + "页)";

        System.Data.SqlClient.SqlConnection conn1 = new SqlConnection();
        conn1.ConnectionString =
           ConfigurationManager.ConnectionStrings["MyBBSConnectionString"].ConnectionString;
        SqlDataReader dr;
        SqlCommand cmd = new SqlCommand();
        cmd.Connection