【问题标题】:Adding Data to a GridView向 GridView 添加数据
【发布时间】:2012-08-15 23:26:06
【问题描述】:

我正在尝试将存储过程中的一些数据显示到我的GridView 中。我正在做的是 onLoad;创建一个 DataTable,向其中添加两行(已调试并且其中肯定有数据),然后;

GridView1.DataSource = 数据表

但是,我的 GridView 每次都返回为空。这是为什么呢?

【问题讨论】:

  • 和更多标签,您的问题,如 asp.net 或 android,以便许多其他用户可以查看您的问题

标签: gridview


【解决方案1】:

试试

 GridView1.DataBind();

加载数据

【讨论】:

  • 哦,如果您希望 GridView 永久链接到数据表,您可能只需要一个 DataBind。到目前为止,GridView 有两行,但没有列,因此没有数据。
【解决方案2】:

在页面加载时我们可以将数据与数据表绑定

protected void Page_Load(object sender, EventArgs e)
{

    con.Open();
    cmd = con.CreateCommand();

    string CommandText1 = "select * from TRAVEL_Preferences_INFO where USER_ID='" + str_USER_ID + "'";
    DB = new SQLiteDataAdapter(CommandText1, con);
    DS.Reset();
    DB.Fill(DS);
    DT = DS.Tables[0];
    grdTravelPreference.DataSource = DT;
    grdTravelPreference.DataBind();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 2014-10-25
    相关资源
    最近更新 更多