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
Du musst angemeldet sein, um einen Kommentar abzugeben.
Erste von allen, die Sie nicht brauchen, um passieren
ComboBox
- by-reference.Wählen Sie den Wert
DataBoud
ComboBox, dies zu tun:Und es wird eine Vorauswahl geben Wert.
InformationsquelleAutor gzaxx
Ich nehme an, das problem ist in dieser Zeile:
In ASP.NET Sie können die
SelectedValue
Eigenschaft über dieText
Eigenschaft einerDropDownList
(wie bei Winforms). Beachten Sie den Unterschied setzen Sie den Wert der text-Eigenschaft. AberListItem.ToString
gibt den text zurück, nicht die value-Eigenschaft.So müssen Sie dies:
oder der gleichen mit
SelectedValue
direkt:InformationsquelleAutor Rango