Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys,
M facing this problem...The listbox selected value doesn't get set in textbox.

on page load
if (!IsPostBack)
           {
               DataTable _dtusers = _objLog.getUser();
               lstbx.DataSource = _dtusers;
               lstbx.DataValueField = _dtusers.Columns["Username"].ToString();
               lstbx.DataTextField = _dtusers.Columns["name"].ToString();
               lstbx.DataBind();
           }


I have assigned listbox the datasource

and on its selected index change

protected void lstbx_SelectedIndexChanged(object sender, EventArgs e)
{
    for (int i = 0; i < lstbx.Items.Count; i++)
    {
        if (lstbx.Items[i].Selected)
        {
            txtUserName.Text = lstbx.Items[i].Value.ToString();
        }
    }

}


Everything works fine...i have already enabled the viewstate and autopostback property to true..When i debug, it shows no error and also shows that value gets set but the value just doesn't show up in the textbox..


please guide me...
Posted

C#
protected void lstbx_SelectedIndexChanged(object sender, EventArgs e)
{        
    txtUserName.Text = lstbx.SelectedItem.ToString();      
}
 
Share this answer
 
v2
try this


C#
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox1.Text = ListBox1.SelectedItem.Text;
        }

//set autopost back property = true;
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" 
 
Share this answer
 

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