Borry
Oct 30th, 2002, 07:25 AM
Hello everybody,
I'm binding a datagrid to a datareader. This works awesome. But now I'm trying to achieve the following :
I want to make my columns smaller then the standard. My columns aren't bound to anything.
This is what I try, but nothing seems to work, cause when I do a columncount from my datagrid, it always returns 0... but when I run the asp page, I see all of my columns.
Private Sub LoadData()
Dim dr As SqlDataReader
Dim oCommand As New SqlCommand()
Dim oConnection As New SqlConnection()
Dim strSQL As String = "SELECT wp.Afdeling, wp.WerkPostTitel, pg.Naam, pg.Voornaam FROM t" & _
"blWerkpostPerPersoon wpp INNER JOIN tblWerkposten wp ON wpp.WerkPostNr = wp.Werk" & _
"PostNr INNER JOIN PersoneelsGegevens.dbo.tblPersGeg pg ON pg.StamNr = wpp.StamNr" & _
" WHERE (wp.Archief = 0) AND (wpp.Archief = 0) ORDER BY wp.Afdeling, wpp.WerkPost" & _
"Nr, pg.Naam"
'Wijs de connectiestring toe aan het nieuw connectieobject
oConnection.ConnectionString = strConnection
'Wijs de query toe aan het nieuwe command object
oCommand.CommandText = strSQL
'Wijs de connectie property van het command object toe aan het connectie object
oCommand.Connection = oConnection
'Open de connectie
oConnection.Open()
'Vul de reader op met de gegevens van het command object
dr = oCommand.ExecuteReader
'Bind de datagrid aan de datareader
dgResults.DataSource = dr
dgResults.DataBind()
'dgResults.Columns().ItemStyle.Width = Unit.Pixel(20)
'Sluit de datareader en de dbase connectie af.
dr.Close()
oConnection.Close()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write(dgResults.Columns.Count)
LoadData()
'Label1.Text = dgResults.Columns.Count
End Sub
I really hope someone could help me out !!!!
On my html page :
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="default.aspx.vb" Inherits="Arbeiders.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" bgColor="#ffffff">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="dgResults" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 108px" runat="server" Height="150px" Width="760px" CellPadding="4" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CC9966">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle Wrap="False" ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
Thanks,
Bjorn
I'm binding a datagrid to a datareader. This works awesome. But now I'm trying to achieve the following :
I want to make my columns smaller then the standard. My columns aren't bound to anything.
This is what I try, but nothing seems to work, cause when I do a columncount from my datagrid, it always returns 0... but when I run the asp page, I see all of my columns.
Private Sub LoadData()
Dim dr As SqlDataReader
Dim oCommand As New SqlCommand()
Dim oConnection As New SqlConnection()
Dim strSQL As String = "SELECT wp.Afdeling, wp.WerkPostTitel, pg.Naam, pg.Voornaam FROM t" & _
"blWerkpostPerPersoon wpp INNER JOIN tblWerkposten wp ON wpp.WerkPostNr = wp.Werk" & _
"PostNr INNER JOIN PersoneelsGegevens.dbo.tblPersGeg pg ON pg.StamNr = wpp.StamNr" & _
" WHERE (wp.Archief = 0) AND (wpp.Archief = 0) ORDER BY wp.Afdeling, wpp.WerkPost" & _
"Nr, pg.Naam"
'Wijs de connectiestring toe aan het nieuw connectieobject
oConnection.ConnectionString = strConnection
'Wijs de query toe aan het nieuwe command object
oCommand.CommandText = strSQL
'Wijs de connectie property van het command object toe aan het connectie object
oCommand.Connection = oConnection
'Open de connectie
oConnection.Open()
'Vul de reader op met de gegevens van het command object
dr = oCommand.ExecuteReader
'Bind de datagrid aan de datareader
dgResults.DataSource = dr
dgResults.DataBind()
'dgResults.Columns().ItemStyle.Width = Unit.Pixel(20)
'Sluit de datareader en de dbase connectie af.
dr.Close()
oConnection.Close()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write(dgResults.Columns.Count)
LoadData()
'Label1.Text = dgResults.Columns.Count
End Sub
I really hope someone could help me out !!!!
On my html page :
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="default.aspx.vb" Inherits="Arbeiders.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" bgColor="#ffffff">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="dgResults" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 108px" runat="server" Height="150px" Width="760px" CellPadding="4" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CC9966">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle Wrap="False" ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
Thanks,
Bjorn