473,624 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databinding a drop down list, hooking into the SelectedIndexCh anged and avoiding the viewstate

I am stuggling with databinding a drop down list, hooking into the SelectedIndexCh anged and attempting to avoid using the viewstate.

The drop down list is quite large so I would prefer to avoid using the view state so I set EnableViewState on the page to false. To enable the drop down list to bind to a datasource I bind it during the OnInit.

I do a response.Write during the SelectedIndexCh anged event to verify that the event fires.

It all works EXCEPT when the first item of the drop down list is reselected after another item is selected. The event just does not fire.

Does this mean that if you want to hook into SelectedIndexCh anged reliably you must use the ViewState?

Regards
Dave A
<%@ Page language="c#" Codebehind="Web Form1.aspx.cs" AutoEventWireup ="false" Inherits="WebAp plication1.WebF orm1" enableViewState ="False"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema" content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:DropDownLi st id="DropDownLis t1" style="Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP: 72px"
runat="server" Width="280px" AutoPostBack="T rue"></asp:DropDownLis t>
</form>
</body>
</HTML>

----

using System;
using System.Collecti ons;
using System.Collecti ons.Specialized ;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Drop DownList DropDownList1;
NameValueCollec tion list = new NameValueCollec tion();

protected WebForm1()
{
list.Add("Do not filter","");
list.Add("abc", "1");
list.Add("def", "2");
list.Add("ghi", "3");
list.Add("jkl", "4");
}
private void Page_Load(objec t sender, System.EventArg s e)
{

}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
DropDownList1.D ataSource = list;
DropDownList1.D ataBind();

//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.DropDownLi st1.SelectedInd exChanged += new System.EventHan dler(this.DropD ownList1_Select edIndexChanged) ;
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void DropDownList1_S electedIndexCha nged(object sender, System.EventArg s e)
{
Response.Write( "Drop down list fired:" + DropDownList1.S electedValue);
}
}
}

Nov 29 '05 #1
2 3019
You maybe should define DropDownList1.D atamember.

I am also struggling with databinding and dropdownlist: It works in a
aspx page but not in an ascx component, do you know why?

Nov 29 '05 #2
If you could provide a cut down example I would love to take a look. This
stuff is all 'too easy' when you read it in the help or in a news group or
in a book but when you are faced with real-world problems the wheels seem to
fall off.

"Nosaj" <ni************ *@gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
You maybe should define DropDownList1.D atamember.

I am also struggling with databinding and dropdownlist: It works in a
aspx page but not in an ascx component, do you know why?

Nov 29 '05 #3

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

Similar topics

8
278
by: Kris Rockwell | last post by:
Hello, I have done the following to bind data to a DropDown box: 1. Drag SQLServer table onto web form to create data connection and data adapter. 2. Generate dataset by right-clicking on the data adapter ad selecting generate dataset.
3
1393
by: Lloyd Sheen | last post by:
I have several apps that use a roll your own approach, but I am embarking on a project which will not allow that with the time constraints. I have gened up a little app to try the databinding approach. Simply it is a page to maintain the Territories table in Northwind (SQL Server). I have two SqlDataAdaptors - one for the list of Territories - on for the individual Territories row (uses parameter to select)
10
4497
by: Krista Lemieux | last post by:
I'm new to ASP.NET and I'm not use to the way things are handled with this technology. I've been told that when I have a control, I should only bind the data to it once, and not on each post back (basically have the data binding done in the If NOT IsPostBack Then statement). How come? How does this information get preserved? Which raises another question. Becuase I want to get away from the spaghetti code approach, I would like to create...
0
1352
by: BryanS | last post by:
I am having trouble trying to link 2 drop down lists and a repeater control. What i want is 2 drop down lists, the first being a list of food categories. When a category is selected the second dropdown is populated with a list of the food belonging to the selected category (this part is working fine). Now I also have a repeater control on the page. When a food in the second dropdown is selected I want the nutritional data for it to be...
0
1029
by: Mythran | last post by:
I wrote an editor for a web control that allows it to list all controls on a page in a drop down box in the property grid. In the EditValue method, I have the following (not all the code, but most of it): ^snip^ ' Create the listbox to display the control id's. listBox = New ListBox() With listBox .BorderStyle = BorderStyle.None
2
1894
by: Chris Davoli | last post by:
I have a problem where my SelectedIndexChanged on a drop down will fire sporadically. When it won't fire, I go into Debug and set a break point on the SelectedIndexChanged event, it will then fire in debug mode, and will also fire after that when not in debug mode. Seems like when I do it once in debug mode it will work after that. I made sure that when I double click on the drop down it goes to the code for the SelectedIndexChanged event,...
8
7568
by: Ed Dror | last post by:
Hi there ASP.NET 2.0 VB & SQL Express Lest take Northwind Categories Products as example I create a table that hold these two together and I create a stored procedure like select ProductID, ProductName, CategoryID, from tblCategoryProducts Where (CategoryID = @CategoryID)
2
6121
by: hwiechers | last post by:
I have two drop down lists on a page. Each one is hooked up to a separate SqlDataSource. The second data source has a ControlParameter set to the selected value of the first drop down. When I set the SelectedValue of the first drop down in Page_Load, the DataBinding event of the second fires twice. This causes the second drop down to have duplicate values. Try as I might I haven't been able to get this to work. Does anyone have a solution...
7
22454
controlbox
by: controlbox | last post by:
I have recently inplemented some drop-down lists (combos) on a page where one is dynamically populated according to the selection of another using the microsoft ajax extensions. I had to set AutoPostBack = true, and enable viewstate in order for the serverside events to fire, but once this was done, all seemed well - so far so good... Also, when the page form is submitted, the Javascript validateForm() function is executed to perform...
0
8675
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
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
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...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
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...
1
2604
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
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
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.