du kan få et her:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GeneratedGridViewPage.aspx.cs" Inherits="GeneratedGridViewPage" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<strong>Eksempel på GridView form genereret af VS2005</strong><br />
<br />
<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="False"
DataKeyNames="PersonId"
DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display." AllowPaging="True" AllowSorting="True">
<Columns>
<asp:BoundField DataField="PersonId" HeaderText="PersonId" ReadOnly="True" SortExpression="PersonId" />
<asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
<asp:BoundField DataField="Adresse" HeaderText="Adresse" SortExpression="Adresse" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
<asp:CheckBoxField DataField="IsActive" HeaderText="IsActive" SortExpression="IsActive" />
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:DemoDatabaseConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:DemoDatabaseConnectionString1.ProviderName %>"
SelectCommand="SELECT [PersonId], [Name], [Age], [Adresse], [City], [Country], [IsActive] FROM [Persons]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
du skal så have sådan en sektion som denne under appsettings i din web.config fil:
<connectionStrings>
<add name="DemoDatabaseConnectionString1" connectionString="Data Source="..." providerName="System.Data.SqlClient" />
</connectionStrings>
men du kan få vs til at generere hele dynen, ved at åbne din database via serverexplorer, og blot trække tabellen ind på din form.
udtrykket her:
<ItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</ItemTemplate>
er bare for at du kan se hvordan du kan gøre det manuelt ... Bind giver dig mulighed for tovejsbinding - Eval giver dig envejs (læsning).
mvh