Web Studyaspnet.blogspot.com Babyneed.blogspot.com

ASP.Net Web Developer Guide

Power By: eXTReMe Tracker Powered by Blogger  
 
 
 
 

 

 
Important Links
 
   
     
 
Sitemap
 
   
   
 
Reference
 
   

Monday, February 13, 2006

Figure 2.8(Chapter 2)

Using a DataGrid Control in ASP.NET
1: <%@ Page Language="VB" %>
2: <%@ Import Namespace="System.Data" %>
3: <%@ Import Namespace="System.Data.SqlClient" %>
4:
5: <script runat="server">
6: Sub Page_Load(Src As Object, e As EventArgs)
7: Dim myConnection As SqlConnection
8: Dim myCommand As SqlDataAdapter
9:
10: myConnection = new _
11: SqlConnection("server=localhost;uid=sa;pwd=;" _
12: & "database=pubs")
13: myCommand = new SqlDataAdapter("SELECT * FROM Authors", _
14: myConnection)
15:
16: Dim ds As DataSet = new DataSet()
17: myCommand.Fill(ds)
18:
19: MyDataGrid.DataSource = ds
20: MyDataGrid.DataBind()
21: End Sub
22: </script>
23:
24: <html><body>
25: <h3><font face="Verdana">
26: Simple Select to a DataGrid Control.
27: </font></h3>
28: <ASP:DataGrid id="MyDataGrid" runat="server"
29: Width="700"
30: BackColor="#ccccff"
31: BorderColor="black"
32: ShowFooter="false"
33: CellPadding=3
34: CellSpacing="0"
35: Font-Name="Verdana"
36: Font-Size="8pt"
37: HeaderStyle-BackColor="#aaaadd"
38: MaintainState="false"
39: />
40: </body></html>
You can see that there is no code to loop through any data. Simply assign the
DataGrid a data source, as shown on line 19, call the DataBind method, and
you’re set to go!

0 Comments:

Post a Comment

<< Home