C# .NET - cannot get the dropdownlist selected item

Asked By muthuraman alexander on 14-Nov-11 12:26 AM
hi ALL
i'm using the dropdown list control in my page
when select some item in the drop down and press the submit button
i need to get the selected item from the drop down
but i getting only the first item not the selected item

i loading the dropown items dynamically from the database

my code is



asp:DropDownList runat="server" Width="120px" ID="drp_SubhurbList"

OnSelectedIndexChanged = "drp_SubhurbList_SelectedIndexChanged" >


<asp:ImageButton runat="server" ID="btnCalculateShipping" OnClick="UpdateButton_Click"

SkinID="Continue" AlternateText="GO" Style="position:absolute" />


protected void UpdateButton_Click(object sender, EventArgs e)


if (drp_SubhurbList != null)

if (drp_SubhurbList.SelectedItem != null && drp_SubhurbList.SelectedItem.Text != string.Empty)



"state"] = string.Empty;


"state"] = drp_SubhurbList.SelectedItem.Text.ToString();


public void bindDropDownList()

//dtCities is a datatable

drp_SubhurbList.DataSource = dtCities;

drp_SubhurbList.DataTextField =


drp_SubhurbList.DataValueField =


it always getting the first item forexample
if i having the items like


and when i select delhi and press submit button
it returning the  chennai for always

please advice me

thanks in advance

Suchit shah replied to muthuraman alexander on 14-Nov-11 12:45 AM
Just enable the AutoPostback propery of the Dropdown list to True and check that out. just do it like below change


asp:DropDownList runat="server" Width="120px" ID="drp_SubhurbList" 

Autopostback="True" OnSelectedIndexChanged = "drp_SubhurbList_SelectedIndexChanged" >


dipa ahuja replied to muthuraman alexander on 14-Nov-11 01:22 AM
while binding dropdownlist add the dropdownlist.DataBind() method

public void bindDropDownList()
    //dtCities is a datatable
    drp_SubhurbList.DataSource = dtCities;
    drp_SubhurbList.DataTextField =
    drp_SubhurbList.DataValueField = "zipcode";

and on submit button click instead of SelectedItem.Text , try the SelectedValue

muthuraman alexander replied to dipa ahuja on 14-Nov-11 05:46 AM
thank u for your reply
i do the same why u had prescriped
but it was not working

i populating the drop dynamically not in the page load

plesase  advice me

thanks in advance