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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Upendra Pratap ShahiPosted Jul 2, 2015, 5:44 AM
RakeshPosted Jul 2, 2015, 3:10 AM
Sujeet SumanPosted Jul 2, 2015, 2:57 AM
Manoj BhoirPosted Jul 2, 2015, 2:49 AM
{
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;
}