Data Controls

How to bind table data to gridview
 
  • Connect via Code :
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;



namespace WebApplication1

{

    public partial class _Default : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            SqlConnection conn = new SqlConnection("Data Source=MANSI\\SQLEXPRESS;  Initial catalog=user;Integrated Security=true;");


            try

            {


                conn.Open();

                string query = "select * from employee";

                SqlDataAdapter da = new SqlDataAdapter(query,conn);

                DataSet ds = new DataSet();

                da.Fill(ds);

                GridView1.DataSource = ds;  //     BIND TO GRID

                GridView1.DataBind();


            }

            catch (Exception)

            {



            }

            finally

            {

                conn.Close();

            }

        }

    }

}

  •  Connect Manually :
http://aspdotnetutility.blogspot.in/p/data-controls.html

















 
GRID VIEW





*********************************************************************

How to bind table to datalist
 
  • Connect via Code :
 
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;



namespace WebApplication1

{

    public partial class _Default : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {


            SqlConnection conn = new SqlConnection("Data Source=MANSI\\SQLEXPRESS;  Initial catalog=user;Integrated Security=true;");


            try

            {


                conn.Open();

                string query = "select * from employee";

                SqlDataAdapter da = new SqlDataAdapter(query,conn);

                DataSet ds = new DataSet();

                da.Fill(ds);

                DataList1.DataSource = ds;  // Bind to datalist

                DataList1.DataBind();


            }

            catch (Exception)

            {



            }

            finally

            {

                conn.Close();

            }

        }

    }

}
  
DATALIST VIEW

*********************************************************************



How to bind table to DetailsView
 
  • Connect via Code :
 
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;



namespace WebApplication1

{

    public partial class _Default : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {


            SqlConnection conn = new SqlConnection("Data Source=MANSI\\SQLEXPRESS;  Initial catalog=user;Integrated Security=true;");


            try

            {


                conn.Open();

                string query = "select * from employee";

                SqlDataAdapter da = new SqlDataAdapter(query,conn);

                DataSet ds = new DataSet();

                da.Fill(ds);

                DetailsView1.DataSource = ds;  // Bind to DetailsView

                DetailsView1.DataBind();


            }

            catch (Exception)

            {



            }

            finally

            {

                conn.Close();

            }

        }

    }

}
  

DetailsView


*********************************************************************










No comments:

Post a Comment