473,761 Members | 10,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databound DropDownList and SelectedIndexCh anged Event issues

Hi, I hope some one can help with this. I have a basic webform with 2
DropDownLists and a single DataGrid. What I am trying to do is populate the
first DDList from a dataset on Form_Load. I then want to use this 1st DDList
to populate the 2nd DDList via the SelectedIndexCh ange Event.

So far so good. all works up to this point.

The next thing I'm trying to do is to use the 2nd DDList value in a queery
to populate the Datagrid also via the SelectedIndexCh ange Event. This is
where I run into the problem: When the 2nd DDList does it's postback it
seems to loose it's Values and the SelectedIndexCh anged Event won't fire.

If I pre-populate the 2nd DDList manually from IDE before runtime, then the
problem disappears.

any Ideas anyone?

Thanks

WebForm1.aspx :
***********

<%@ Page Language="vb" AutoEventWireup ="false" Codebehind="Web Form1.aspx.vb"
Inherits="shop. WebForm1"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:DropDownLi st id="DDL_Top_Cat egory" style="Z-INDEX: 101;
LEFT: 24px; POSITION: absolute; TOP: 8px"
runat="server" AutoPostBack="T rue"
Width="112px"></asp:DropDownLis t>
<asp:DataGrid id="DG_Selectio ns" style="Z-INDEX: 103; LEFT:
16px; POSITION: absolute; TOP: 64px"
runat="server"> </asp:DataGrid>
<asp:DropDownLi st id="DDL_Sub_Cat egory" style="Z-INDEX: 102;
LEFT: 24px; POSITION: absolute; TOP: 32px"
runat="server" Width="112px"
AutoPostBack="T rue"></asp:DropDownLis t></form>
</body>
</HTML>
WebForm1.aspx.v b :
**************

Imports System.Data.Sql Client

Public Class WebForm1
Inherits System.Web.UI.P age
Public DS_Selections As New DataSet

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents DDL_Top_Categor y As
System.Web.UI.W ebControls.Drop DownList
Protected WithEvents DDL_Sub_Categor y As
System.Web.UI.W ebControls.Drop DownList
Protected WithEvents DG_Selections As System.Web.UI.W ebControls.Data Grid

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack = True Then

'Populate DDL_Top_Categor y

Dim ds1 As New DataSet

Dim sConn As SqlConnection = New SqlConnection(" Data
Source=*****;In itial Catalog=*****;U ser Id=*****;Passwo rd=*****")
Dim sq1 As SqlDataAdapter = New SqlDataAdapter( "SELECT * FROM
Product_Top_Cat egory", sConn)

sq1.Fill(ds1)

DDL_Top_Categor y.DataSource = ds1.Tables(0)
DDL_Top_Categor y.DataTextField =
ds1.Tables(0).C olumns(1).Colum nName.ToString
DDL_Top_Categor y.DataValueFiel d =
ds1.Tables(0).C olumns(2).Colum nName.ToString
DDL_Top_Categor y.DataBind()

End If
End Sub

Private Sub DDL_Top_Categor y_SelectedIndex Changed(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
DDL_Top_Categor y.SelectedIndex Changed

'Fill DDL_Sub_Categor y depending on DDL_Top_Categor y Selection
DDL_Sub_Categor y.Items.Clear()

Dim ds1 As New DataSet

Dim sConn As SqlConnection = New SqlConnection(" Data
Source=*****;In itial Catalog=*****;U ser Id=*****;Passwo rd=*****")
Dim sq1 As SqlDataAdapter = New SqlDataAdapter( "SELECT * FROM
Product_Sub_Cat egory WHERE Category_Level= '" & DDL_Top_Categor y.SelectedValue
& "'", sConn)

sq1.Fill(ds1)

DDL_Sub_Categor y.DataSource = ds1.Tables(0)
DDL_Sub_Categor y.DataTextField =
ds1.Tables(0).C olumns(1).Colum nName.ToString
DDL_Sub_Categor y.DataValueFiel d =
ds1.Tables(0).C olumns(2).Colum nName.ToString
DDL_Sub_Categor y.DataBind()

End Sub

Private Sub DDL_Sub_Categor y_SelectedIndex Changed(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
DDL_Sub_Categor y.SelectedIndex Changed

'Fill DG_Selections depending on DDL_Sub_Categor y Selection
Dim sConn As SqlConnection = New SqlConnection(" Data
Source=*****;In itial Catalog=*****;U ser Id=*****;Passwo rd=*****")
Dim sq1 As SqlDataAdapter = New SqlDataAdapter( "SELECT * FROM
Products WHERE Product_ID='" & DDL_Sub_Categor y.SelectedValue & "' AND
Product_In_Use= 1", sConn)

sq1.Fill(DS_Sel ections)

DG_Selections.D ataSource = DS_Selections
DG_Selections.D ataBind()

End Sub
End Class

--
Before you judge a man, walk a mile in his shoes. Then who cares! You are a
mile away and you have his shoes.
Nov 21 '05 #1
0 2286

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9094
by: Donal | last post by:
I have 3 related dropdowns. When the 1st is changed, the 2nd is updated, and when the 2nd is changed, the 3rd is updated. When i change the 1st dropdown (sites), the SelectedIndexChanged fires and the 2nd dropdown (spaces) is updated. However, 'spaces' no longer has a SelectedIndexChanged event. Where did it go to? If I change 'spaces' (2nd dropdown) before it gets updated by the 1st (sites), its SelectedIndexChanged is fired and the...
1
3749
by: Mike D | last post by:
I've populated a DropDownList with information from SQL. I click a Search Button on my Web Form that triggers the SelectedIndexChanged event. However, the SelectedItem.Value still returns the first line item in the dropdownlist, even though I've clicked on something else. I'm a newbie here, what am I missing.
4
5482
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
2
17031
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
1
578
by: sergeyr3 | last post by:
Hey guys, I am new here, so i hope this works out: I have a datagrid which I populate with data from XML file. In EditItemTemplate I have a dropdownlist. How do I fire myDataGrid_UpdateCommand upon SelectedIndexChanged event in the dropdownlist? thank you. -Sergey <ASP:DataGrid id="myDataGrid" runat="server"
4
1946
by: David | last post by:
Hi all, I am doing this in a web page... I have a dropdownlist that autopostback. This sets me a filter criteria for items to display in a datalist. In the datalist, I have edit capabilities, which opens a text box. When I click Update for the datalist (edit), then for some reason, the
1
2031
by: DJ | last post by:
I have a DropDownList in Visual Web Developer that is databound to a SQL Database. Whenever the web page is opened the DropDownList is automatically filled with the first item in the table. My question is, how do I set it so that the DropDownList is empty until a value is selected?
2
1512
by: KerryL | last post by:
How do I update the value of a databound column within my datagrid from within the SelectedIndexChanged event of a dropdownlist, also found within my datagrid? I believe I need to determine the row I'm on but I don't know how to get that.
2
3305
by: jnoody | last post by:
The problem I am having is with the SelectedIndexChanged event not always firing or the SelectedIndex property not being correct when the event does fire. The code is below, but here are some details first. The DropDownList is actually a custom control called DropDownListWithCommandEvent that inherits from DropDownList. The reason I have created this is to create a DropDownList that will bubble a Command event to the containing...
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.