IT Community - Software Programming, Web Development and Technical Support

Problem in my DropDownList SelectedIndexChanged.

This is a discussion on Problem in my DropDownList SelectedIndexChanged. within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi friendz! I have been building web page involving use of dynamic data binding to drop down menus. I have ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-10-2007, 05:11 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Question Problem in my DropDownList SelectedIndexChanged.

Hi friendz!

I have been building web page involving use of dynamic data binding to drop down menus. I have populated the drop down menu with my items during page_load event I have also set the autopost property of the drop down widget to true. But even then the event " DropDownList1_SelectedIndexChanged " is not getting fired!

Here is my code snippet:

Code:
using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Web; 
using System.Web.SessionState; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.HtmlControls; 
using System.IO; 
using System.Net; 
using System.Net.Sockets; 
using System.Timers; 

namespace SpawnRandomMpi 
{ 
public class WebForm1 : System.Web.UI.Page 
{ 
protected System.Web.UI.WebControls.Label Title; 
protected System.Web.UI.HtmlControls.HtmlInputFile FileUploaded; 
protected System.Web.UI.WebControls.Label FileerrorLabel; 
protected System.Web.UI.WebControls.TextBox IPSolaris; 
protected System.Web.UI.WebControls.Label IPAddLabel; 
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2; 
protected System.Web.UI.WebControls.ListBox ListBox1; 
protected System.Web.UI.WebControls.Button Problem1Button; 
protected System.Web.UI.WebControls.DropDownList DropDownList1; 
protected System.Web.UI.WebControls.Label RandomLabel; 
protected System.Web.UI.WebControls.TextBox nBox; 
protected System.Web.UI.WebControls.TextBox mBox; 
protected System.Web.UI.WebControls.Panel RandomPanel; 
protected System.Web.UI.WebControls.Panel FilePanel; 
protected System.Web.UI.WebControls.Label FinalLabel; 
protected System.Web.UI.WebControls.Label LabelFile; 
protected System.Web.UI.WebControls.Label CurrentStatus; 
protected System.Web.UI.WebControls.DataGrid DataGrid1; 
//Sql Definations 

protected System.Web.UI.WebControls.TextBox TextBox1; 
protected System.Web.UI.WebControls.Label Label1; 
protected System.Web.UI.WebControls.Button submit; 
protected System.Web.UI.WebControls.Label result; 
protected ArrayList method,values; 
// String of FileName (has to be static else after postback value nulls) 
//dont know why 
protected static string filename; 

private void Page_Load(object sender, System.EventArgs e) 
{ 
if(!IsPostBack) 
{ 
RandomPanel.Visible=false; 
method=new ArrayList(); 
method.Add("File"); 
method.Add("Random"); 
DropDownList1.DataSource=method; 
DropDownList1.DataBind(); 
DataGrid1.Visible=false; 
filename = ""; 
} 
else 
{ 
if((this.Page.Request.Params.Get("__EVENTTARGET")).CompareTo("DropDownList1")==0) 
{ 
DataGrid1.Visible=false; 
} 
} 

} 

#region Web Form Designer generated code 
override protected void OnInit(EventArgs e) 
{ 
// 
// CODEGEN: This call is required by the ASP.NET Web Form Designer. 
// 
InitializeComponent(); 
base.OnInit(e); 
} 

/// <summary> 
/// Required method for Designer support - do not modify 
/// the contents of this method with the code editor. 
/// </summary> 
private void InitializeComponent() 
{ 
///// 
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged); 
///// 
this.Load += new System.EventHandler(this.Page_Load); 
((System.ComponentModel.ISupportInitialize)(this.sqldataset)).EndInit(); 
} 

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) 
{ 
if(DropDownList1.SelectedIndex==0 ) 
{ 
FilePanel.Visible=true; 
RandomPanel.Visible=false; 
} 
else 
{ 
FilePanel.Visible=false; 
RandomPanel.Visible=true; 
} 
FileStream fs = new FileStream("c:\\temp\\stamp.txt", FileMode.Append); 
StreamWriter w2 = new StreamWriter(fs,System.Text.Encoding.Default); 

// Write into file to check if the event is fired 
w2.Write("i fired!"); 
fs.Close(); 
w2.close(); 
}
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-11-2007, 04:26 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Smile Re: Problem in my DropDownList SelectedIndexChanged.

I think there is a bug in DropDownList... if items have same VALUE then switching between those items doesn't trigger the event. Also selecting items with same VALUE doesn't work correctly... i.e. if there are two items in ddl..

Item 1 : Text : B ; Value : 1
Item 2 : Text : A ; Value : 1

In the above senario if you select item 2 it will select item 1 instead... since that is the first matching instance with the value of the item you actually selected (item 2)!!!

Is there a work around for this ?? I was thinking to override the value property and concatenate the index while setting the value and parsing the index out while reading it back.. but so far I haven't been able to write the required code... any help is appreciated.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-11-2007, 11:47 PM
latchu latchu is offline
D-Web Trainee
 
Join Date: Sep 2007
Posts: 21
latchu is on a distinguished road
Default Re: Problem in my DropDownList SelectedIndexChanged.

give
Code:
autopostback="True"
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create dropdownlist at runtime shaalini ASP and ASP.NET Programming 1 02-14-2008 08:16 PM
how to bind values of onedropdownlist to another dropdownlist in another page? poornima ASP and ASP.NET Programming 0 02-03-2008 09:07 PM
is it possible to bind data's in one dropdownlist in the selectedindex change of othe kingmaker C# Programming 4 01-18-2008 02:43 AM
DropdownList in Editable Datagrid shaalini ASP and ASP.NET Programming 3 10-26-2007 06:07 AM
How to get the index value of the dropdown from the dropdownlist item Sathish Kumar C# Programming 0 03-12-2007 12:14 PM


All times are GMT -7. The time now is 06:29 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0