Click here to Skip to main content
15,914,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Iam trying to get listbox selected value by using thelistbox_Indexchanged event, but I am unable to get the selected index or selected value. Please help me out.

Here's the code I've written so far (dt1 is a DataTable).
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        dt1.Clear();
        dt1 = g1.Getusers();
        for (i = 0; i < dt1.Rows.Count; i++)
        {
            if (ListBox1.SelectedValue.ToString() == dt1.Rows[i][1])
            {
                TextBox1.Text = dt1.Rows[i][1].ToString();
                TextBox2.Text = dt1.Rows[i][2].ToString();
                DropDownList1.SelectedValue = dt1.Rows[i][3].ToString();
            }
        }
    }


thanks.
Posted
Updated 16-Nov-10 23:50pm
v2
Comments
Sandeep Mewara 17-Nov-10 5:41am    
Sorry! Did I miss your issue? What's the question?

1 solution

Well, you are comparing:
ListBox1.SelectedValue.ToString() == dt1.Rows[i][1]
Looks like you have not used DEBUGGER and seen the values. it looks to me that the comparison is not correct.

Please debug and see if the values are selected.

One more thing, do make sure that you are not re-binding the LitBox1 with the dataset before this selectedindexchange event fires.
 
Share this answer
 
Comments
shwetha_m6 17-Nov-10 6:54am    
hi thanks for ur replay.. but i dunno y this selected_indexcahnged event is not taking effect unless i click any button on screen...!! otherwise i'l be able to get the value...while debugging...! please suggest me..
Sandeep Mewara 17-Nov-10 7:27am    
Set the property to AutoPostback true such that whenever selection is done it will get auto postback and then you can see the value in the selected change event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900