DROPDOWN SELECTEDINDEX PROBLEM

I

in da club

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;

}
 
K

Karthik D V [C#,ASP.NET - MCAD]

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.
 
I

in da club

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;

}
 
I

in da club

ok i solved the problem . The problem is that SelectIndexChanged event fired
after Page_Load event. Then I checked my code and solved it..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top