programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Tuesday, August 19, 2014

Bind Data to textbox control in inside of gridview Using C# Example

Bind Data to textbox control in inside of gridview:

In this post we describe how to bind textbox control which is use to inside the grid.In the past post we learn how to bind dropdownlist and how to use dropdownlist with in grid. And also give a example of tooltip on control. In this tutorial blog we give many Examples rerated to grid view these are :

Gridview Related Post:

Example of C# for Bind Data

Now we consider one more gridview example in which we consider textbox with in grid and bind it by sql data table.

Bind Data to textbox:

Consider a table which has two columns StateID and StateName. Make sql connection and fetch data form sql server.

Code for textbox binding Example:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Exampleoftemplate.aspx.cs" Inherits="Exampleoftemplate" %>

<!DOCTYPE html PUBLIC " //W3C//DTD XHTML 1.0 Transitional//EN" " transitional.dtd">

<html xmlns="">
<head runat="server">
    <title>textbox control in inside of gridview</title>
    <form id="form1" runat="server">
    <div align="center">
        <br />       
            <h3>Bind Data to textbox control in inside of gridview Example </h3>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
            Height="258px" Width="559px" >
         <asp:TemplateField HeaderText="SNo" ItemStyle HorizontalAlign="Center">
                                <%#Container.DataItemIndex+1 %>
                            <ItemStyle HorizontalAlign="Center"></ItemStyle>
         <asp:TemplateField HeaderText="State ID" ItemStyle HorizontalAlign="Center">
                                <asp:Label ID="lblStateID" runat="server" Text='<%# Eval("StateID") %>'></asp:Label>
                            <ItemStyle HorizontalAlign="Center"></ItemStyle>
         <asp:TemplateField HeaderText="Name of State" ItemStyle HorizontalAlign="Center">
                                <asp:Label ID="lblName" runat="server" Text='<%# Eval("StateName") %>'></asp:Label>
                            <ItemStyle HorizontalAlign="Center"></ItemStyle>

            <HeaderStyle BackColor="#3333FF" BorderColor="#FF99FF" BorderStyle="Groove"
                BorderWidth="1px" ForeColor="White" />

C# Code for textbox control binding Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Exampleoftemplate : System.Web.UI.Page
    string _connectionstring;
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            _connectionstring = @"Data Source=PARIJAT PC\PARIJAT;Initial Catalog=Database1;Integrated Security=True;Pooling=False";// create connection....
            BindData();// make function .......and call here........

    private void BindData()

            string _sql = "select StateID,StateName from States";//sql Query
            SqlConnection _connection = new SqlConnection(_connectionstring);
            SqlCommand _command = new SqlCommand(_sql, _connection);
            SqlDataAdapter _adapter = new SqlDataAdapter(_command);
            DataTable datatable = new DataTable();

            GridView1.DataSource = datatable;  //bind grid                              GridView1.DataBind();


Other Related Post:

No comments:

Post a Comment