【问题标题】:Why is not this gridview loading the results?为什么这个 gridview 不加载结果?
【发布时间】:2013-06-02 02:58:20
【问题描述】:

我正在尝试用搜索结果填充网格视图。这是我的“AddDropClasses”页面的 UI:

加载此页面时,我希望gridview 填充当前用户的当前课程,我使用Register 表执行此操作。这是我的代码:

 protected void Page_Load(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection();
    con.ConnectionString = Userfunctions.GetConnectionString();
    con.Open();

    string query = "select * from RegisterTable where StudentID='" + MyGlobals.currentID + "'";

    SqlDataAdapter adap = new SqlDataAdapter(query, con);

    DataTable tab = new DataTable();

    adap.Fill(tab);

    showCourses.DataSource = tab;


}

我通过单击另一个页面的按钮来加载(进入)该页面。问题是,该表没有显示任何结果。当我调试时,我意识到 Myglobals.ID 具有我已经期望的值。这里有什么问题?有人可以帮忙吗?;

谢谢

【问题讨论】:

    标签: asp.net database gridview


    【解决方案1】:

    您忘记绑定showCourses。在showCourses.DataSource = tab;之后添加showCourses.DataBind();

    【讨论】:

    • 非常感谢,成功了。您能否简要解释一下数据绑定的作用?
    • 对于任何 asp.net 数据绑定控件,您需要调用实际填充控件的DataBind()。看看here、here 和here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 2019-12-18
    • 2020-01-03
    • 2011-06-29
    • 1970-01-01
    相关资源
    最近更新 更多