473,394 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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(object sender, System.EventArgs e)

{

int TotalP=0;

SortedList hash =new SortedList ();

SqlConnection baglantim=con.MyConnect ();

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

{

hash.Add (j,j);

}


dd.DataTextField ="Value";

dd.DataValueField ="Key";

dd.DataSource=hash;

dd.DataBind();
if (!Page.IsPostBack )

{

DataGrid1.DataSource = con.FillGrid (baglantim,0);

DataGrid1.DataBind();

}

}

private void dd_SelectedIndexChanged(object sender, System.EventArgs e)

{

// Label1.Text =dd.SelectedIndex.ToString() ;

string PageN;
PageN=dd.SelectedIndex.ToString();

Label1.Text = PageN;

}
Mar 21 '07 #1
4 2090
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(object sender, System.EventArgs e)

{

int TotalP=0;

SortedList hash =new SortedList ();

SqlConnection baglantim=con.MyConnect ();

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

{

hash.Add (j,j);

}


dd.DataTextField ="Value";

dd.DataValueField ="Key";

dd.DataSource=hash;

dd.DataBind();
if (!Page.IsPostBack )

{

DataGrid1.DataSource = con.FillGrid (baglantim,0);

DataGrid1.DataBind();

}

}

private void dd_SelectedIndexChanged(object sender, System.EventArgs e)

{

// Label1.Text =dd.SelectedIndex.ToString() ;

string PageN;
PageN=dd.SelectedIndex.ToString();

Label1.Text = PageN;

}
Mar 21 '07 #2
I got it from my page..
<option selected="selected" 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_SelectedIndexChanged(object sender, System.EventArgs e)

{

// Label1.Text =dd.SelectedIndex.ToString() ;

string PageN;
PageN=dd.SelectedItem.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="selected" 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_SelectedIndexChanged(object sender, System.EventArgs e)

{

// Label1.Text =dd.SelectedIndex.ToString() ;

string PageN;
PageN=dd.SelectedItem.Value;

Label1.Text = PageN;

}
Mar 21 '07 #4
ok i solved the problem . The problem is that SelectIndexChanged 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
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...
5
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....
4
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....
5
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...
2
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....
3
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...
2
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...
1
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>". ...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...

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.