469,926 Members | 2,412 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

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 1986
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by HalaszJ | last post: by
5 posts views Thread by Kris Rockwell | last post: by
1 post views Thread by John Wright | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.