<asp:GridView ID="GridView1" runat="Server" AutoGenerateColumns="False" BorderWidth="1" DataKeyNames="AutoID" AutoGenerateEditButton="True" OnRowEditing="EditRecord" OnRowCancelingEdit="CancelRecord" OnRowUpdating="UpdateRecord" CellPadding="4" HeaderStyle-HorizontalAlign="left" OnRowDeleting="DeleteRecord" RowStyle-VerticalAlign="Top" ForeColor="#333333" GridLines="None" ShowHeaderWhenEmpty="true"> <EmptyDataTemplate> <asp:Label ID="norecord" Text="no data was found" runat="server"></asp:Label> </EmptyDataTemplate> <Columns> <asp:BoundField DataField="AutoID" HeaderText="AutoID" /> <asp:TemplateField HeaderText="Page Name"> <ItemTemplate> <%# Eval("PageName") %> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtPageName" runat="Server" Text='<%# Eval("PageName") %>' Columns="30"></asp:TextBox> <asp:RequiredFieldValidator ID="req1" runat="Server" Text="*" ControlToValidate="txtPageName"></asp:RequiredFieldValidator> </EditItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333" VerticalAlign="Top" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView>
Imports System.Data.SqlClient Public Class _Default Inherits System.Web.UI.Page Dim connStr As String = ConfigurationManager.ConnectionStrings("Cstring").ToString Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) BindData() End Sub ''' <summary> ''' Bind data to the grid ''' </summary> Private Sub BindData() Dim conn As SqlConnection = New SqlConnection(connStr) Dim dAd As SqlDataAdapter = New SqlDataAdapter("select * from Page", conn) Dim dSet As DataSet = New DataSet Try dAd.Fill(dSet) GridView1.DataSource = dSet GridView1.DataBind() Catch ee As Exception lblMessage.Text = ee.Message.ToString Finally dSet.Dispose() dAd.Dispose() conn.Close() conn.Dispose() End Try End Sub End Class
<?xml version="1.0"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="Cstring" connectionString="data source=.\SQLEXPRESS;Integrated Security=sspi;Database=Test;" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration>
GridView1.DataSource = dSet
GridView1.DataSource = dSet.Tables(0)
AutoGenerateColumns="False"
AutoGenerateColumns="True"
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)