Skip to main content

Gridview Using Boundfeild In C# And Asp.Net

Here I will code you how to bind the values into Gridview from database by using bound field. Bound field allows grid view to show the specified columns. It enables developers to restrict the columns to the grid. Also enables columns to change the header text for columns.

Output Preview :

Database Structure:
Aspx Code:
<head runat="server">
    <title> Fourthbottle </title>
    <form id="form1" runat="server">
    <asp:GridView ID="Grd_BoundFeild" AutoGenerateColumns="false" runat="server">
    <asp:BoundField HeaderText="Mobile Brand" DataField="Brand" />
    <asp:BoundField HeaderText="Mobile Model" DataField="Model" />
    <asp:BoundField HeaderText="Mobile Color" DataField="color" />
    <asp:Label id="lblstatus" runat="server"></asp:Label>

C# 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 GRD
    public partial class GRD_BOUNDFEILD : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)

        protected void BindGrid()
            SqlConnection con = new SqlConnection("your Connection string");
            string Query = "select * from Table1";
            SqlDataAdapter da = new SqlDataAdapter(Query, con);
            DataSet DS = new DataSet();
                Grd_BoundFeild.DataSource = DS;
            catch (Exception es)
                lblstatus.Text = es.Message.ToString();