The GridView control solves a problem that has plagued developers for years: data presentation. The GridView control generates simple HTML tables, so information within a GridView is presented to the end user in a familiar , cleanly formatted, tabular structure.
the GridView control provides the following functionality: ¦database table-like presentation of data ¦table headers and footers ¦paging ¦sorting ¦style modification through templates ¦customizable columns for advanced editing
To Use
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h1>Address Book</h1> <asp:GridView id="grid" runat="server" /> </asp:Content>
To BInd
using System; using System.Data.SqlClient; public partial class AddressBook : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); } } private void BindGrid() { SqlConnection conn; SqlCommand comm; SqlDataReader reader; string connectionString =ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString; conn = new SqlConnection(connectionString); comm = new SqlCommand("SELECT EmployeeID, Name, City, State, MobilePhone " + "FROM Employees", conn); try { conn.Open(); reader = comm.ExecuteReader(); grid.DataSource = reader; grid.DataBind(); reader.Close(); } finally { conn.Close(); } } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|