Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 25th, 2005, 04:44 AM
Authorized User
 
Join Date: Oct 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default What Event Exactly?

I need to populate a dropdown listbox named "sub category" once the user the clicks his desired selection in the dropdown listbox named "category" e.g. clothing has subcategories like gent's clothes and ladies clothes.

I need to know which event i have to use? Im not sure in what event i have to put my code in exactly.Could someone give me some demonstration thru code please..thanx

 
Old October 25th, 2005, 03:13 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Use the SelectedIndexChanged event of the "Category" dropdownlist.
Jim

 
Old October 25th, 2005, 04:24 PM
Authorized User
 
Join Date: Oct 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

okay i did try onSelectedIndexChanged ="populate", embeded this value in the server control tag as : <asp:dropdownlist id="cboCat" width="150" onSelectedIndexChanged="populate" runat="server"/>.

The populate procedure is as follows:
Sub populate(sender as object, e as eventargs)
      'code to populate subcategory dropdown list box
 End Sub

But it is not working , whenever i select any other item in the category listbox the first item gets selected automatically.

I did set the AutoPostBack property to true, but with this i get the first item of the dropdown listbox selected everytime i try to select any other item i.e. if there are four items in the order clothing, food, stores, homeliving and i select stores then clothing gets selected automatically.
And even if i set AutoPostBack ="False" the same thing happens but this time only on the first click r selection it happens.

why is that? I jus want this dropdown listbox to leave with the value i selected .

Please look in to it and let me know what to do...thanx



 
Old October 25th, 2005, 05:57 PM
Authorized User
 
Join Date: Oct 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

okay let me just explain the heart of the problem. There is this dropdownlist populated with vales from SQL Server 7.0 database i.e. "clothing","food","stores" and "homeliving".
Now just the first time when the user selects any value from this list the first value "clothing" gets selected and on the status bar it comes "opening page http://maxood/5040/watal.aspx" .This means the page gets loaded again.

Now how can i stop it!!??

Here is my code for the page load event:

Dim strConnection as String = "server=Maxood;database=watal;user id=sa;password=;"
  Dim strSql as String = "Select categoryname from category"

  Dim objConn1 as New SqlConnection(strConnection)
  Dim cmdCat as New SqlCommand(strSql,objConn1)


  objConn1.Open()
  cboCat.DataSource = cmdCat.ExecuteReader(System.Data.CommandBehavior.C loseConnection)
  cboCat.DataTextField = "categoryname"
  cboCat.DataBind()



  strSql = "Select * from city"
  Dim objConn2 as New SqlConnection(strConnection)
  Dim cmdCity as New SqlCommand(strSql,objConn2)

  objConn2.Open()

  cbocity.DataSource =cmdCity.ExecuteReader(System.Data.CommandBehavior .CloseConnection)
  cboCity.DataTextField="city"
  cboCity.DataBind()

Please explain!!




 
Old October 26th, 2005, 12:24 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

When AutoPostBack is set to true on a control, the page gets posted back. You need this to be set to true in order to grab the value of the selected item in one dropdown in order to populate the second one.

For values you do not want re-populated on postback, you need an IF Not IsPostBack statement:
IF Not IsPostBack Then
 Dim strSql as String = "Select categoryname from category"

  Dim objConn1 as New SqlConnection(strConnection)
  Dim cmdCat as New SqlCommand(strSql,objConn1)


  objConn1.Open()
  cboCat.DataSource = cmdCat.ExecuteReader(System.Data.CommandBehavior.C loseConnection)
  cboCat.DataTextField = "categoryname"
  cboCat.DataBind()



  strSql = "Select * from city"
  Dim objConn2 as New SqlConnection(strConnection)
  Dim cmdCity as New SqlCommand(strSql,objConn2)

  objConn2.Open()

  cbocity.DataSource =cmdCity.ExecuteReader(System.Data.CommandBehavior .CloseConnection)
  cboCity.DataTextField="city"
  cboCity.DataBind()
End IF

End Sub

 
Old October 26th, 2005, 01:57 AM
Authorized User
 
Join Date: Oct 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thnax a lot for this tip. I need to know what event is generated when a user selects a new item in a dropdown list box.
I have to populate the subcategories dropdown list once the user selects the item in the category listbox.For example if the categories are clothing, foods, stores and home living and the user selects clothing then the subcategory listbox should be populated with values like gents clothes, ladies clothes, etc.

Please give me an exaple through code...thanx.

 
Old October 26th, 2005, 09:24 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I already told you. Use the selectedindex event of the category drop down list. I am not going to write code for you. Just create the event for the drop down, and place your code to populate the other drop down there.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Event - Sender & Event args dash dev C# 2005 9 December 9th, 2007 07:24 AM
Event Firing tobriain C# 1 June 12th, 2007 08:19 AM
first event bostek Excel VBA 2 September 7th, 2006 02:13 AM
About Button event and Keydown event zhangxujun1981 XSLT 1 March 6th, 2004 04:59 AM
how to override an event with an event? blah VB.NET 2002/2003 Basics 5 November 13th, 2003 03:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.