Newbie: Datagrid not displaying

G

Guest

I've used ASP a lot in the past, and I'm trying to switch to asp.net and use
datagrids (bigger difference than I thought). I am also fairly new to Visual
Studio 2003. I've created my datagrid in the designer (connection, adapter,
grid, etc). I can click on my adapter and preview the data, and it works.
However, the webpage itself doesn't display any data. I suspect the issue is
because my connections are created but I'm not filling the grid - but I'm not
sure of the correct code for that. The code is below.

Webform1.aspx:
....
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 176px; POSITION:
absolute; TOP: 136px" runat="server" Width="408px" DataSource="<%# Lgds1 %>">
</asp:DataGrid>
</form>
</body>
....


Webform1.aspx.vb:

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.Lgds1 = New web1.LGDS
CType(Me.Lgds1, System.ComponentModel.ISupportInitialize).BeginInit()
'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "LGUnmanaged", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("HostName", "HostName"), New
System.Data.Common.DataColumnMapping("Domain", "Domain"), New
System.Data.Common.DataColumnMapping("IP", "IP"), New
System.Data.Common.DataColumnMapping("MAC", "MAC"), New
System.Data.Common.DataColumnMapping("MACVendor", "MACVendor"), New
System.Data.Common.DataColumnMapping("OS", "OS"), New
System.Data.Common.DataColumnMapping("UserName", "UserName")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT HostName, Domain, IP,
MAC, MACVendor, OS, UserName FROM dbo.LGUnmanaged"
Me.SqlSelectCommand1.CommandTimeout = 180
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = <edited out>
'
'Lgds1
'
Me.Lgds1.DataSetName = "LGDS"
Me.Lgds1.Locale = New System.Globalization.CultureInfo("en-US")
CType(Me.Lgds1, System.ComponentModel.ISupportInitialize).EndInit()



End Sub
Protected WithEvents SqlDataAdapter1 As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents Lgds1 As web1.LGDS
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here


End Sub

Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)
End Sub
End Class
 
G

Guest

Thanks Cor!

This helped solve my issue. I had finally figured out the correct 'fill'
code before your response, but I kept putting it after the 'generated code' -
and it never worked. I put it where the link suggested and everything
worked. Putting it under the automatically generated code and it gets
deleted at every build.

Thanks for the response!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top