ddlSubCategory.Items.Clear()
ds=returnds(""select category_name,cetegory_id from category"")
'suppose ds is dataset
ddlSubCategory.DataSource = ds
ddlSubCategory.DataTextField = "Category_Name"
ddlSubCategory.DataValueField = "Category_ID"
ddlSubCategory.DataBind()
=============================================
On Wed, Jul 1, 2009 at 1:12 AM, vickyk <[email protected]> wrote:
>
> 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 ??
>