472,983 Members | 2,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

Databound DropDownList and SelectedIndexChanged 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 SelectedIndexChange 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 SelectedIndexChange 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 SelectedIndexChanged 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="WebForm1.aspx.vb"
Inherits="shop.WebForm1"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DDL_Top_Category" style="Z-INDEX: 101;
LEFT: 24px; POSITION: absolute; TOP: 8px"
runat="server" AutoPostBack="True"
Width="112px"></asp:DropDownList>
<asp:DataGrid id="DG_Selections" style="Z-INDEX: 103; LEFT:
16px; POSITION: absolute; TOP: 64px"
runat="server"></asp:DataGrid>
<asp:DropDownList id="DDL_Sub_Category" style="Z-INDEX: 102;
LEFT: 24px; POSITION: absolute; TOP: 32px"
runat="server" Width="112px"
AutoPostBack="True"></asp:DropDownList></form>
</body>
</HTML>
WebForm1.aspx.vb :
**************

Imports System.Data.SqlClient

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

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents DDL_Top_Category As
System.Web.UI.WebControls.DropDownList
Protected WithEvents DDL_Sub_Category As
System.Web.UI.WebControls.DropDownList
Protected WithEvents DG_Selections As System.Web.UI.WebControls.DataGrid

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

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

End Sub

#End Region

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

'Populate DDL_Top_Category

Dim ds1 As New DataSet

Dim sConn As SqlConnection = New SqlConnection("Data
Source=*****;Initial Catalog=*****;User Id=*****;Password=*****")
Dim sq1 As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM
Product_Top_Category", sConn)

sq1.Fill(ds1)

DDL_Top_Category.DataSource = ds1.Tables(0)
DDL_Top_Category.DataTextField =
ds1.Tables(0).Columns(1).ColumnName.ToString
DDL_Top_Category.DataValueField =
ds1.Tables(0).Columns(2).ColumnName.ToString
DDL_Top_Category.DataBind()

End If
End Sub

Private Sub DDL_Top_Category_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DDL_Top_Category.SelectedIndexChanged

'Fill DDL_Sub_Category depending on DDL_Top_Category Selection
DDL_Sub_Category.Items.Clear()

Dim ds1 As New DataSet

Dim sConn As SqlConnection = New SqlConnection("Data
Source=*****;Initial Catalog=*****;User Id=*****;Password=*****")
Dim sq1 As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM
Product_Sub_Category WHERE Category_Level='" & DDL_Top_Category.SelectedValue
& "'", sConn)

sq1.Fill(ds1)

DDL_Sub_Category.DataSource = ds1.Tables(0)
DDL_Sub_Category.DataTextField =
ds1.Tables(0).Columns(1).ColumnName.ToString
DDL_Sub_Category.DataValueField =
ds1.Tables(0).Columns(2).ColumnName.ToString
DDL_Sub_Category.DataBind()

End Sub

Private Sub DDL_Sub_Category_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DDL_Sub_Category.SelectedIndexChanged

'Fill DG_Selections depending on DDL_Sub_Category Selection
Dim sConn As SqlConnection = New SqlConnection("Data
Source=*****;Initial Catalog=*****;User Id=*****;Password=*****")
Dim sq1 As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM
Products WHERE Product_ID='" & DDL_Sub_Category.SelectedValue & "' AND
Product_In_Use=1", sConn)

sq1.Fill(DS_Selections)

DG_Selections.DataSource = DS_Selections
DG_Selections.DataBind()

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 2211

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

Similar topics

1
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...
1
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...
4
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...
2
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...
1
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...
4
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...
1
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...
2
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...
2
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.