windowsgm
windowsgm

Reputation: 1616

Adding Data to a GridView

I'm trying to display some data from a Stored Procedure into my GridView. What I'm doing is onLoad; creating a DataTable, adding two rows to it (debugged and there's definitely data in them) and then;

GridView1.DataSource = DataTable

However my GridView comes back empty every time. Why is this?

Upvotes: 0

Views: 245

Answers (2)

Siddharam Padamgond
Siddharam Padamgond

Reputation: 1

On The page load we can bind the data with data table

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();
}

Upvotes: 0

FJT
FJT

Reputation: 2083

Try

 GridView1.DataBind();

to load the data

Upvotes: 2

Related Questions