There is a table in a database having country names and their id.
I fetched the data from the table to a dropdownlist,which i did by
writing:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Persist Security
Info=False;Integrated Security=SSPI;server=CODENAME;database=try");
        SqlCommand com = new SqlCommand("Select CountryId,CountryName
from country", con);
        SqlDataAdapter da = new SqlDataAdapter(com);
        DataSet ds = new DataSet();
        da.Fill(ds);
        countryddl.DataSource = ds;
        countryddl.DataBind();
    }

now i want to display the corresponding ID of the country when the
country is selected so i
wrote this and postback is ON.

protected void countryddl_SelectedIndexChanged(object sender,
EventArgs e)
    {
        int sel_val = Convert.ToInt32(Convert.ToString
(countryddl.SelectedValue));
        Response.Write(sel_val);
}

still it always gives ID of the 1st country no matter what i choose.
how to solve this ??

Reply via email to