grid. if it is empty, there will be no data, otherwise there will be a grid
with data in it.
"Iain Kirk" <iain.removeme@z-uk.com> wrote in message
news:etTPKMm%23DHA.2484@TK2MSFTNGP12.phx.gbl...
> Alvin thanks for replying, i tried what you said and i then got an error
in
> IE that said 'The server tag is not well formed.'. I think i may be
missing
> the binding bit, how do i test to make sure it is bound and there is data
in
> the DataSet?
>
> Here is my code to save space i have only included what i believe to be
> relevent if you need it all i can post it.
>
> <%@ Page Language="VB" %>
> <%@ import Namespace="System.Data" %>
> <%@ import Namespace="System.Data.SqlClient" %>
> <script runat="server">
> Dim ConnectionString As String =
> "server=(local);database=commerce;trusted_connection=true"
> Dim SQLCmd As String = "select CategoryID as [Cat ID], CategoryName as
> [Cat Name] from CMRC_Categories"
> Dim SQLDDL as String = "SELECT CategoryID, CategoryName FROM
> CMRC_Categories"
>
> Sub Page_Load(Sender As Object, E As EventArgs)
> Dim myConnection As New SqlConnection(ConnectionString)
> Dim myCommand As New SqlCommand(SQLCmd, myConnection)
>
> myConnection.Open()
>
> DataGrid1.DataSource =
> myCommand.ExecuteReader(CommandBehavior.CloseConnection)
> DataGrid1.DataBind()
> End Sub
>
> Function GetCategories() as DataSet
> Dim ddlDataSet as DataSet = New DataSet()
> Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(SQLDDL,
> ConnectionString)
>
> myDataAdapter.Fill(ddlDataSet, "Categories")
>
> Return ddlDataSet
> End Function
>
> </script>
>
>
> <html>
> <head>
> </head>
> <body style="FONT-FAMILY: arial">
> <form runat="server">
> <p>
> <asp:datagrid id="DataGrid1" runat="server"
> EnableViewState="False" ForeColor="Black" BackColor="White"
CellPadding="3"
> GridLines="None" CellSpacing="1">
> <HeaderStyle font-bold="True" forecolor="white"
> backcolor="#4A3C8C"></HeaderStyle>
> <ItemStyle backcolor="#DEDFDE"></ItemStyle>
> </asp:datagrid>
> </p>
> <p>
> <asp:DropDownList id="DropDownList1" runat="server"
> DataSource="<%# GetCategories() %>" DataTextField="CategoryName"
> DataValueField="CategoryID" width="200"></asp:DropDownList>
> </p>
> </form>
> </body>
> </html>
>
>
> "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> news:e5ebjEc%23DHA.3820@TK2MSFTNGP09.phx.gbl...
> > your complete code should look like this
> > dropdown.datatextfield = "CategoryID"
> > dropdown.datavaluefield="CategoryName"
> > then bind assuming you have tested the dataset to see if it is not null
> and
> > it has at least one row.
> >
> > if this does not work for you, post your code
> >
> > --
> > Regards,
> > Alvin Bruney [ASP.NET MVP]
> > Got tidbits? Get it here...
> >
http://tinyurl.com/3he3b > > "Iain Kirk" <iain.removeme@z-uk.com> wrote in message
> > news:ed6zQsZ%23DHA.2656@TK2MSFTNGP11.phx.gbl...
> > > Thanks for prompt reply, I have already tried that before posting
> > previously
> > > and tried it once more just to confirm but it still doesn't work, any
> more
> > > ideas would be great.
> > >
> > > Cheers, Iain
> > >
> > >
> > > "Anatoly" <anatoly@hotmail.com> wrote in message
> > > news:u1g2nUU%23DHA.1452@TK2MSFTNGP09.phx.gbl...
> > > > Set DataTextField and DataValueField
> > > >
> > > >
> > > > "Iain Kirk" <iain.removeme@z-uk.com> wrote in message
> > > > news:uIGtybS%23DHA.2308@TK2MSFTNGP11.phx.gbl...
> > > > > Being a bit of a novice any help or pointers would be appreciated.
> > > > >
> > > > > I am building a web page that populates a DropDowList from a table
> in
> > > SQL,
> > > > > for testing purposes i have a simple page that displays a datagrid
> > with
> > > > the
> > > > > same data, now this does work so i know the data is there but the
> > > > > dropdownlist is empty. If anyone could show me where i'm going
wrong
> i
> > > > would
> > > > > be very thankful.
> > > > >
> > > > > Here is the code i am using:
> > > > >
> > > > > <%@ Page Language="VB" %>
> > > > > <%@ import Namespace="System.Data" %>
> > > > > <%@ import Namespace="System.Data.SqlClient" %>
> > > > > <script runat="server">
> > > > > Dim ConnectionString As String =
> > > > > "server=(local);database=commerce;trusted_connection=true"
> > > > > Dim CommandText as String = "SELECT CategoryID, CategoryName
> FROM
> > > > > Categories"
> > > > >
> > > > > Sub Page_Load(Sender As Object, E As EventArgs)
> > > > > Dim myConnection As New SqlConnection(ConnectionString)
> > > > > Dim myCommand As New SqlCommand(CommandText, myConnection)
> > > > >
> > > > > myConnection.Open()
> > > > >
> > > > > DataGrid1.DataSource =
> > > > > myCommand.ExecuteReader(CommandBehavior.CloseConnection)
> > > > > DataGrid1.DataBind()
> > > > > End Sub
> > > > >
> > > > > Function GetCategories() as DataSet
> > > > > Dim ddlDataSet as DataSet = New DataSet()
> > > > > Dim myDataAdapter as SqlDataAdapter = New
> > > > SqlDataAdapter(CommandText,
> > > > > ConnectionString)
> > > > >
> > > > > myDataAdapter.Fill(ddlDataSet, "Categories")
> > > > >
> > > > > Return ddlDataSet
> > > > > End Function
> > > > >
> > > > > </script>
> > > > >
> > > > > <html>
> > > > > <head>
> > > > > </head>
> > > > > <body style="FONT-FAMILY: arial">
> > > > > <form runat="server">
> > > > > <p>
> > > > > <asp:datagrid id="DataGrid1" runat="server"
> > > > > EnableViewState="False" ForeColor="Black" BackColor="White"
> > > > CellPadding="3"
> > > > > GridLines="None" CellSpacing="1">
> > > > > <HeaderStyle font-bold="True" forecolor="white"
> > > > > backcolor="#4A3C8C"></HeaderStyle>
> > > > > <ItemStyle backcolor="#DEDFDE"></ItemStyle>
> > > > > </asp:datagrid>
> > > > > </p>
> > > > > <p>
> > > > > <asp:DropDownList id="DropDownList1" runat="server"
> > > > > DataSource="<%# GetCategories %>" width="200"></asp:DropDownList>
> > > > > </p>
> > > > > </form>
> > > > > </body>
> > > > > </html>
> > > > >
> > > > >
> > > > > TIA Iain
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
>