Wie legen Sie Wert in der Dropdownlist asp.net mit C#

habe ich eine Methode zum Auffüllen der dropdownlist in asp.net mit C#

public void get_country_box_populated(ref System.Web.UI.WebControls.DropDownList dropDown, bool add_initial_text)
{
    dropDown.Items.Clear();
    //dropDown.Items.Add(0,"Select Any Country");
    var context = new db_vmartEntities();
    var query = from c in context.tbl_countary
                where c.status == true
                select new { c.countary_id, c.countary_name };

    var dictionary = new Dictionary<int, string>();
    if (add_initial_text)
    {
        dictionary.Add(0, "Select Any Country");
    }
    foreach (var item in query)
    {
        dictionary.Add(item.countary_id, item.countary_name);
    }
    dropDown.DataTextField = "Value";
    dropDown.DataValueField = "Key";
    dropDown.DataSource = dictionary;  //Dictionary<int, string>
    dropDown.DataBind();
}

jetzt brauche ich, um wählen Sie einen Standard-Wert auf "Seite Bearbeiten" so etwas wie dieses.

store_registration my_store = str.get_store_by_id(Session["user"].ToString(), sid);
c.get_country_box_populated(ref countary_box,false);
countary_box.Text = countary_box.Items.FindByValue(my_store.countary).ToString();

aber Wert nicht gesetzt, weil patteren ist wie diese

Dictionary<key,value>
Dictionary<5,Pakistan>
Dictionary<8,India>
Dictionary<9,Iran>
Dictionary<6,UK>

jede Hilfe oder Anleitung, wenn ich kann einstellen, Großbritannien in der dropdownlist bei mystore.Land Wert ist 6

InformationsquelleAutor syed Ahsan Jaffri | 2013-02-07

Schreibe einen Kommentar