i have data in a table .now i need to get the data when page is loaded the data which are in the database should be display.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manoj BhoirRank #599 · 4K reputationPosted Jul 1, 2015, 10:49 PM EDT
{
if (!IsPostBack)
{
GridView1.DataSource = GetData();
GridView1.DataBind();
}
}
DataTable GetData()
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["testconection"].ConnectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("select id , name from tableName ",con))
{
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(dt);
}
}
return dt;
}
Sujeet SumanRank #790 · 2.9K reputationPosted Jul 1, 2015, 10:57 PM EDT
RakeshRank #397 · 6.3K reputationPosted Jul 1, 2015, 11:10 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jul 2, 2015, 1:44 AM EDT