D
Dave1031
I am new to ASP.net and am building my site using Visual Web Developer 2005
Express.
I have no problem adding a "GridView" control to my page, wiring it to a
data connection and having it display in a browser. I can do all of this
with deag and drop functionality and do not have to write a line of code.
But if I need more flexibility and try to do the same thing
programmatically, the gtid will not display on my page. I get no error, juts
that nothing displays.
Listed below is the code I used. I got this code from an example in the
book ASP.net Data Web Controls. Can anyone tell me why it's not working?
I guess more fundamentally, what happene3d to the datagrid control in the
Web Developer Express? I have a "GridView" control but no "DataGrid"
control. Are they the same thing or is DataGrid nm longer supported?
Thanks
Dave
CODE:
<body>
<form id="form1" runat="server">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'1. Create a connection
Const strConnString As String = _
"server=localhost;uid=sa;pwd=;database=pubs"
Dim objConn As New SqlConnection(strConnString)
'2. Create a command object for the query
Const strSQL As String = "SELECT * FROM authors"
Dim objCmd As New SqlCommand(strSQL, objConn)
'3. Create the DataAdapter
Dim objDA As New SqlDataAdapter()
objDA.SelectCommand = objCmd
'4. Populate the DataSet and close the connection
Dim objDS As New DataSet()
objDA.Fill(objDS)
objConn.Close()
'Finally, specify the DataSource and call DataBind()
dgAuthors.DataSourceID = "SqlDataSource2"
dgAuthors.DataBind()
End Sub
</script>
<asp:datagrid id="dgAuthors" runat="server" AllowPaging="True"
ShowFooter="True" />
.....
Express.
I have no problem adding a "GridView" control to my page, wiring it to a
data connection and having it display in a browser. I can do all of this
with deag and drop functionality and do not have to write a line of code.
But if I need more flexibility and try to do the same thing
programmatically, the gtid will not display on my page. I get no error, juts
that nothing displays.
Listed below is the code I used. I got this code from an example in the
book ASP.net Data Web Controls. Can anyone tell me why it's not working?
I guess more fundamentally, what happene3d to the datagrid control in the
Web Developer Express? I have a "GridView" control but no "DataGrid"
control. Are they the same thing or is DataGrid nm longer supported?
Thanks
Dave
CODE:
<body>
<form id="form1" runat="server">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'1. Create a connection
Const strConnString As String = _
"server=localhost;uid=sa;pwd=;database=pubs"
Dim objConn As New SqlConnection(strConnString)
'2. Create a command object for the query
Const strSQL As String = "SELECT * FROM authors"
Dim objCmd As New SqlCommand(strSQL, objConn)
'3. Create the DataAdapter
Dim objDA As New SqlDataAdapter()
objDA.SelectCommand = objCmd
'4. Populate the DataSet and close the connection
Dim objDS As New DataSet()
objDA.Fill(objDS)
objConn.Close()
'Finally, specify the DataSource and call DataBind()
dgAuthors.DataSourceID = "SqlDataSource2"
dgAuthors.DataBind()
End Sub
</script>
<asp:datagrid id="dgAuthors" runat="server" AllowPaging="True"
ShowFooter="True" />
.....