Hey,
I'm having trouble making this work ... I create the DataGrid and try to connect it with the query in the BindData() function, but apparently the function's trying to run before the datagrid gets created?
Any ideas?
Thanks,
Rick
RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website
I'm having trouble making this work ... I create the DataGrid and try to connect it with the query in the BindData() function, but apparently the function's trying to run before the datagrid gets created?
Any ideas?
Thanks,
Rick
Code:
<% @Import Namespace="System" %>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Init(sender as Object, e as EventArgs)
tTitle.Text="Hey you!"
tHeader.Text="Welcome!"
tContent.Controls.Add(new Label())
Dim c
Dim d=1
For Each c in tContent.Controls
If d = tContent.Controls.Count Then
c.Text = "This is a site to test out ASP.NET and see what cool stuff it can do!"
End If
d=d+1
Next
tContent.Controls.Add(new DataGrid())
d=1
For Each c in tContent.Controls
If d = tContent.Controls.Count Then
c.ID = "myDG"
End If
d=d+1
Next
End Sub
Sub Page_Load(sender as Object, e as EventArgs)
' BindData()
End Sub
Sub BindData()
Dim myConnection as New SqlConnection("server=SERVER;uid=UID;pwd=PWD;database=DB")
Const strSQL as String = "SELECT id, Name FROM names ORDER BY id"
Dim myCommand as New SqlCommand(strSQL, myConnection)
myConnection.Open()
myDG.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
myDG.DataBind()
myConnection.Close()
End Sub
</script>
<html>
<head><title><asp:Literal id="tTitle" Text="The Website Name Goes Here" runat="server" /></title></head>
<body>
<table style="width:770px;border:1px solid black;">
<tr>
<td style="width:150px;background-color:#EEEEEE;"><asp:Literal id="tMenu" Text="<a href='text.aspx'>test...</a>" runat="server" /></td>
<td valign="top">
<h1><asp:Literal id="tHeader" Text="Welcome to the Website!" runat="server" /></h1>
<asp:PlaceHolder id="tContent" runat="server" />
</td>
</tr>
</table>
</body>
</html>
RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website