Bind Data to asp.net textbox control in inside of gridview Using C# Example
Bind Data to asp.net 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:
- How to Bind Gridview Form database.
- Show gridview Row Details.
- Templatefield in gridview
- Introduction of Asp.net grid view Control.
- Example of Templatefield in gridview.
- Example of DropDownList inside GridView
- Introduction of Asp.net grid view Control.
- Checkbox in ASP.NET GridView
- Ckeckbox list example-using-javascript.
- Display tooltip from database for dropdownlist items in asp.net c# example
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 asp.net 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>textbox control in inside of gridview</title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<br />
<h3>Bind Data to asp.net textbox control in inside of
gridview Example </h3>
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="false"
Height="258px"
Width="559px"
>
<Columns>
<asp:TemplateField HeaderText="SNo"
ItemStyle HorizontalAlign="Center">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="State
ID" ItemStyle HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblStateID"
runat="server"
Text='<%# Eval("StateID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name of
State" ItemStyle HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblName"
runat="server"
Text='<%# Eval("StateName") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#3333FF"
BorderColor="#FF99FF"
BorderStyle="Groove"
BorderWidth="1px"
ForeColor="White"
/>
</asp:GridView>
</div>
</form>
</body>
</html>
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()
{
try
{
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();
_adapter.Fill(datatable);
GridView1.DataSource = datatable;
//bind grid .........here GridView1.DataBind();
}
catch
{
throw;
}
}
}
Other Asp.net Related Post:
- In asp.net how to upload image
- Asp.netweb api in asp.net programming
- How to fill data into drop down list by Sql.
- How to archive many selection in drop
- Dynamically create data table and bind
- Show grid view row details in to tool.
- Ajax update panel with drop down list
- Select index change in drop down list
- Example of session in asp.net
- Session Management.
- RequiredField validator.
- image size before Uploading.
- Cloud Service Introduction
- Cloud Service Provider
Comments
Post a Comment