Microsoft Grid View Part - I

hi friends, in the 1429 hijri, i once again teach you the gridview in easy manner with images and more explanation please read all the part of this serious to understand the grid view. so now please go step wise.

Step 1:
Database

I created a database called mysql and saved it in the same folder which have table called sqltest with fields.

Step 2:

Drag the grid view from the toolbox


Step 3:

now on the Default.aspx.cs or whatever you given the name of form write this coding

using System;
using System.Data;
/* Please remember to import SqlClient namespace */
using System.Data.SqlClient;

public partial class GridView_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/* Check whether the page is post back or not */

if (!Page.IsPostBack)
{
BindData();
}
}

private void BindData()
{
SqlConnection con= new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|mysql.mdf;Integrated Security=True;User Instance=True");
SqlDataAdapter ad = new SqlDataAdapter("select * from sqltest",con);
DataSet ds = new DataSet();
ad.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}

The Output is :

0 comments: