Print Page | Close Window

I can’t repopulate my drop down after sel

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=985
Printed Date: 28 March 2026 at 9:10am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: I can’t repopulate my drop down after sel
Posted By: davisbm
Subject: I can’t repopulate my drop down after sel
Date 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




Replies:
Posted By: MorningZ
Date 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


Posted By: davisbm
Date 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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net