473,569 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DROPDOWN SELECTEDINDEX PROBLEM

I have a datagrid and a dropdown in my page. I want to fill dropdown with my
pagenumbers. When a user change the dropdown selected index i wnt to display
the result on label1. Anytime i change the dropdown index it returns zero ..
What is the problem ?

private void Page_Load(objec t sender, System.EventArg s e)

{

int TotalP=0;

SortedList hash =new SortedList ();

SqlConnection baglantim=con.M yConnect ();

for (int j=1;j<5;j++)

{

hash.Add (j,j);

}


dd.DataTextFiel d ="Value";

dd.DataValueFie ld ="Key";

dd.DataSource=h ash;

dd.DataBind();
if (!Page.IsPostBa ck )

{

DataGrid1.DataS ource = con.FillGrid (baglantim,0);

DataGrid1.DataB ind();

}

}

private void dd_SelectedInde xChanged(object sender, System.EventArg s e)

{

// Label1.Text =dd.SelectedInd ex.ToString() ;

string PageN;
PageN=dd.Select edIndex.ToStrin g();

Label1.Text = PageN;

}
Mar 21 '07 #1
4 2100
Hi I have faced the same problem a long time back. I cameup with other
solution.

Instead of using the selectedIndex property , use SelectedItem
property.

in da club wrote:
I have a datagrid and a dropdown in my page. I want to fill dropdown with my
pagenumbers. When a user change the dropdown selected index i wnt to display
the result on label1. Anytime i change the dropdown index it returns zero ..
What is the problem ?

private void Page_Load(objec t sender, System.EventArg s e)

{

int TotalP=0;

SortedList hash =new SortedList ();

SqlConnection baglantim=con.M yConnect ();

for (int j=1;j<5;j++)

{

hash.Add (j,j);

}


dd.DataTextFiel d ="Value";

dd.DataValueFie ld ="Key";

dd.DataSource=h ash;

dd.DataBind();
if (!Page.IsPostBa ck )

{

DataGrid1.DataS ource = con.FillGrid (baglantim,0);

DataGrid1.DataB ind();

}

}

private void dd_SelectedInde xChanged(object sender, System.EventArg s e)

{

// Label1.Text =dd.SelectedInd ex.ToString() ;

string PageN;
PageN=dd.Select edIndex.ToStrin g();

Label1.Text = PageN;

}
Mar 21 '07 #2
I got it from my page..
<option selected="selec ted" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>

i tried the following it always returns 1 .. No change..
private void dd_SelectedInde xChanged(object sender, System.EventArg s e)

{

// Label1.Text =dd.SelectedInd ex.ToString() ;

string PageN;
PageN=dd.Select edItem.Value;

Label1.Text = PageN;

}
Mar 21 '07 #3
You should probably cast "sender" to a DropDownList and use that instead of
"dd".
--
Thom
"in da club" wrote:
I got it from my page..
<option selected="selec ted" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>

i tried the following it always returns 1 .. No change..
private void dd_SelectedInde xChanged(object sender, System.EventArg s e)

{

// Label1.Text =dd.SelectedInd ex.ToString() ;

string PageN;
PageN=dd.Select edItem.Value;

Label1.Text = PageN;

}
Mar 21 '07 #4
ok i solved the problem . The problem is that SelectIndexChan ged event fired
after Page_Load event. Then I checked my code and solved it..


Mar 21 '07 #5

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

Similar topics

1
1635
by: HalaszJ | last post by:
Is there no work around for this? >-----Original Message----- >I have asked this question on about every board I can >think of and I have yet to get an answer, so If anyone >would know I imagine it would be here. > >I have a datagrid, and inside of it in an edit item >template I have a drop down list, I want to be able to >have that...
5
10807
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value. I have tried setting various values to represent the default value with little success. Essentially I am looking to have the first item in the list...
4
1854
by: Simon Harvey | last post by:
Hi all, Am I being really stupid here: myDropDown.SelectedIndex = 2 I think this line should set the dropdown control's selected item to 2. But nothing seems to be happening on the page. The dropdown just maintains its default value (element 0).
5
3340
by: david | last post by:
I have a question in the following. Any one could give me a help? Thanks David The dataset is declared and created at Class level. My source code is here: Private Sub lstPatientID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstPatientID.SelectedIndexChanged txtDebug.Text &=...
2
3055
by: 23s | last post by:
I have a dropdown bound to a dataview. The binding assigns the dropdown with a SelectedIndex of 0. There is a msgbox in the SelectedIndexChanged event that displays the SelectedIndex property. There is a button that programatically sets the .SelectedIndex property of the dropdownlist to -1. I am consistantly observing the following 2...
3
4418
by: devNorway | last post by:
I have been struggling with a problem for days now, and searched for related problems and solutions but had no luck. I have two dropdown listboxes where the first is populated in page load and the second is populated based on the input in the first. The first dropdown is inside a "If Not Page.IsPostBackThey" if loop. Both have autopostback...
2
6985
markrawlingson
by: markrawlingson | last post by:
Hi guys, I have a bunch of drop down lists on a page, with a checkbox beside each one that relates to each one respectively. When a user selects an option from the drop down, the checkbox is automatically checked, if the user unchecks the checkbox, the dropdown list is automatically reset to "select" which is the default option. What I'm...
1
1179
by: John Wright | last post by:
I have a dropdown that I load a list of values from a database. If I have more that one value returned from a search I want to populate the dropdown and have the first value be "<Select Run>". Then have the person use the dropdown to select the item. If only one item is found, then I show the item in the dropdown and load its values without...
0
7323
acoder
by: acoder | last post by:
Problem The select object's add method doesn't append options to the end of the list. Browser Internet Explorer Example The Javascript code for appending an option element at the end of a select dropdown list: var opt = document.createElement("option"); opt.name = "optName";
0
7700
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...
0
7924
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. ...
0
8125
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...
0
7974
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...
0
5219
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...
0
3653
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...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
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...

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.