GridView BoundField Example in ASP.NET C#

In this article i will show you, How to use BoundField of GridView in ASP.NET C#. Actually, BoundField is the Default field of GridView Control, used for DataBinding purpose. In my previous article i have already use this field with SQL DataSource control. Check mentioned below link:

[Video Contain BoundField + SQLDataSource + ADO.NET]

Now, Learn, How to create BoundField manually also bind them using ADO.NET Technology with Database table. First to create a database table, insert some data into table. Prepare BoundField like this:

  <asp:GridView ID="g1" runat="server" AutoGenerateColumns="false">

            <asp:BoundField DataField="Id" HeaderText="Identification No" />
            <asp:BoundField DataField="Name" HeaderText="Name of User" />


Code Behind Code:

using System;
using System.Web.UI;
using System.Data.SqlClient;
using System.Configuration;

public partial class BoundFieldExample : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)

    private void bindGrid()
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        SqlCommand cmd= new SqlCommand();
        cmd.CommandText = "select * From [usertable]";
        cmd.Connection =con;
        SqlDataReader rd= cmd.ExecuteReader();
        g1.DataSource =rd;

Code Generates the following output:

GridView BoundField Example in ASP.NET C#


Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites