GridView da TextBox
Kullanımı
Merhaba arkadaşlar. Bu
makalemizde GridView nesnesinde TextBox alanın nasıl kullanıldığını göreceğiz.
ItemTemplate içerisine
aşağıda görüldüğü gibi TextBox nesnesini ekleyeceğiz.
GridView nesnesinin
AutoGenerateColumns özelliğini False yapın.
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" BackColor="White" Text='<%# Eval("JobTitle") %>' />
</ItemTemplate>
Default.aspx.cs
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.OleDb;
public partial class _Default :
System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
OleDbConnection baglan = new
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source= " + Server.MapPath("~/App_Data/northwind.accdb")
+ ";");
baglan.Open();
OleDbCommand cmd = new
OleDbCommand("Select
FirstName,LastName,JobTitle From Customers", baglan);
OleDbDataAdapter
da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
baglan.Close();
}
}
Default.aspx
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default"
%>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="False"
CellPadding="4"
ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle
BackColor="White"
ForeColor="#284775"
/>
<Columns>
<asp:BoundField DataField="FirstName"
HeaderText="İsim"
/>
<asp:BoundField DataField="LastName"
HeaderText="Soyad"
/>
<asp:TemplateField HeaderText="İş">
<ItemTemplate>
<asp:TextBox ID="TextBox1"
runat="server"
BackColor="White"
Text='<%# Eval("JobTitle") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999"
/>
<FooterStyle BackColor="#5D7B9D"
Font-Bold="True"
ForeColor="White"
/>
<HeaderStyle BackColor="#5D7B9D"
Font-Bold="True"
ForeColor="White"
/>
<PagerStyle BackColor="#284775"
ForeColor="White"
HorizontalAlign="Center"
/>
<RowStyle BackColor="#F7F6F3"
ForeColor="#333333"
/>
<SelectedRowStyle
BackColor="#E2DED6"
Font-Bold="True"
ForeColor="#333333"
/>
<SortedAscendingCellStyle
BackColor="#E9E7E2"
/>
<SortedAscendingHeaderStyle
BackColor="#506C8C"
/>
<SortedDescendingCellStyle
BackColor="#FFFDF8"
/>
<SortedDescendingHeaderStyle
BackColor="#6F8DAE"
/>
</asp:GridView>
<br />
<br />
</div>
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki makalede
görüşmek üzere. Bahadır ŞAHİN