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

Example of C# for Bind Data to Textbox inside gridview control:

C# code for Sql Data binding  to text box inside Gridview:

In this post we give an example for taking control with in control. And then bind second control by Sql data base. For this take a gridview and a textbox control in this grid template. In This asp.netprogramming tutorial we give many other grid view related posts, here we listed some important post of related to gridview :-

Gridview Related Post: textbox inside gridview:

Now today we give one more Example related to textbox control and gridview control in Fetch the Data From Sql database and bind textbox.

.Aspx page 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" "">

<html xmlns="">
<head runat="server">
    <title>textbox control in inside of gridview</title>
    <form id="form1" runat="server">
    <div style="">
        <br />       
            <h3>C# code for Sql Data binding to textbox inside gridview: </h3>
        <asp:GridView ID="grd" 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="labelStateID" runat="server" Text='<%# Eval("StateID") %>'></asp:Label>
                            <ItemStyle HorizontalAlign="Center"></ItemStyle>
         <asp:TemplateField HeaderText="Name of State" ItemStyle-HorizontalAlign="Center">
                                <asp:Label ID="labelName" runat="server" Text='<%# Eval("StateName") %>'></asp:Label>
                            <ItemStyle HorizontalAlign="Center"></ItemStyle>

            <HeaderStyle BackColor="#990000" BorderColor="#CC33FF" BorderStyle="Dotted"
                BorderWidth="2px" ForeColor="#009933" />
bind textbox inside of gridview in
Bind textbox inside of gridview in

.Aspx.cs page C# code for textbox control 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();
            grd.DataSource = datatable;  //bind grid .....................

Other programming related Post:

No comments:

Post a Comment