Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - I can’t repopulate my drop down after sel
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

I can’t repopulate my drop down after sel

 Post Reply Post Reply
Author
davisbm View Drop Down
Newbie
Newbie


Joined: 02 January 2003
Location: United States
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote davisbm Quote  Post ReplyReply Direct Link To This Post Topic: I can’t repopulate my drop down after sel
    Posted: 13 March 2003 at 9:57am

I am having trouble repopulating my drop down list in ASP.NET when I select and Item.  It loads correctly but when I select an item the drop down list becomes empty. I know it is and issue with the sutopost property but I can't figure it out.  This used to work when I was using and Access database but now it does't when I am using and SQL Server DB.

Here is the code:

sub Page_Load(obj as Object, e as EventArgs)
            if not Page.IsPostBack then
                Label2.Text = "Welcome, Administrator. <br>1. To edit jobs see the blue Data " & _
                    " Grid below and choose the edit option at the end. <br> 2. To insert a new job enter the correct information under the grid in the blanks<br>" & _
                    "3. To delete jobs select the proper JobID below in the drop-down box and select the button. <br>" & _
                    "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<b>**** The Date Posted field and Title field is required ****</b> "
   
                objConn.open()
      
                'Declare the string
                dim strcom2 as string
                strcom2 = "Select JobID FROM Jobnet"
   
                'sets up the command and reader to execute the command and retrieve the data
                dim objcommand2 AS New SQLCommand(strcom2, objConn)
                dim objreader as SQLDataReader
                objreader = objcommand2.ExecuteReader
   
                'binds the data to the CourseId dropdownlist
                ddjobid.DataSource = objreader
                ddjobid.DataBind()
                ddjobid.Items.Insert(0, new ListItem("<--Select JobID-->", ""))
   
                'closes the reader
                objreader.Close()
   
                BindGrid()
           end if
    end sub

 

The Server Control:

<asp:DropDownList id="ddjobid" runat="server" datatextfield="JobID" AutoPostBack="true" datavaluefield="JobID"></asp:DropDownList>

 

Thanks,

Brad

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 13 March 2003 at 11:45am
can you post some more complete code?

for instance.. where and how is "ddjobid" declared/set ?
Contribute to the working anarchy we fondly call the Internet
Back to Top
davisbm View Drop Down
Newbie
Newbie


Joined: 02 January 2003
Location: United States
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote davisbm Quote  Post ReplyReply Direct Link To This Post Posted: 13 March 2003 at 1:30pm

Here is some more code:  I don't know if this will help but here goes.

 

<%@ Page Language="VB" Debug="true" %>
<%@ Register TagPrefix="Menu" TagName="Nav" Src="pubnav.ascx" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SQLClient" %>
<script runat="server">

         'define the connection
             dim objConn as new SQLConnection ("data source=Localhost; Initial Catalog=WestOhioUMCWebData;" &  _
                        "User id = WebData_sa; Password = BDW0CUMC;" & _
                        "Persist security info = true; Packet size=4096")
  
   
    sub Page_Load(obj as Object, e as EventArgs)
            if not Page.IsPostBack then
                Label2.Text = "Welcome, Administrator. <br>1. To edit jobs see the blue Data " & _
                    " Grid below and choose the edit option at the end. <br> 2. To insert a new job enter the correct information under the grid in the blanks<br>" & _
                    "3. To delete jobs select the proper JobID below in the drop-down box and select the button. <br>" & _
                    "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<b>**** The Date Posted field and Title field is required ****</b> "
   
                objConn.open()
      
                'Declare the string
                dim strcom2 as string
                strcom2 = "Select JobID FROM Jobnet"
   
                'sets up the command and reader to execute the command and retrieve the data
                dim objcommand2 AS New SQLCommand(strcom2, objConn)
                dim objreader as SQLDataReader
                objreader = objcommand2.ExecuteReader
   
                'binds the data to the CourseId dropdownlist
                ddjobid.DataSource = objreader
                ddjobid.DataBind()
                ddjobid.Items.Insert(0, new ListItem("<--Select JobID-->", ""))
   
                'closes the reader
                objreader.Close()
   
                BindGrid()
           end if
    end sub

 

Sub Delete_Job(obj as object, e as EventArgs)
            'define the connection
            dim objConn as new SQLConnection ("data source=Localhost; Initial Catalog=WestOhioUMCWebData;" &  _
                        "User id = WebData_sa; Password = BDW0CUMC;" & _
                        "Persist security info = true; Packet size=4096")
   
            Dim strcom as string
            strcom = "DELETE FROM JobNet Where JobId=" & ddjobid.SelectedItem.Value & " "
   
            dim objCmd as New SQLCommand(strcom, objConn)
            objCmd.Connection.Open()
   
            try
                objCmd.ExecuteNonQuery()
   
            catch ex as Exception
                Response.Write("error updating the Database")
            end try
   
            'Declare the string
            dim strcom2 as string
            strcom2 = "Select JobID FROM Jobnet"
   
            'sets up the command and reader to execute the command and retrieve the data
            dim objcommand2 AS New SQLCommand(strcom2, objConn)
            dim objreader as SQLDataReader
            objreader = objcommand2.ExecuteReader
   
            'binds the data to the CourseId dropdownlist
            ddjobid.DataSource = objreader
            ddjobid.DataBind()
            ddjobid.Items.Insert(0, new ListItem("<--Select JobID-->", ""))
   
            'closes the reader
            objreader.Close()
   
            BindGrid()
    end sub

</script>

 

 

 

HTML

 

 

<body>
    <table align="left" border="0">
        <tbody

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.