protected void Page_Load(object sender, EventArgs e) { DropDownList1.DataSource = rm.Rooms; DropDownList1.DataValueField = "roomid"; DropDownList1.DataTextField = "roomname"; DropDownList1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { string selectvalue = DropDownList1.SelectedValue; int roomindex = Convert.ToInt32(selectvalue); Room selectroom = rm.Rooms.SingleOrDefault<Room>(room => room.roomid == roomindex); GridView1.DataSource = selectroom.Assets; GridView1.DataBind(); }
postback
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DropDownList1.DataSource = rm.Rooms; DropDownList1.DataValueField = "roomid"; DropDownList1.DataTextField = "roomname"; DropDownList1.DataBind(); } }
string selectvalue = DropDownList1.SelectedItem;
string selectvalue = DropDownList1.Text;
string selectvalue = DropDownList1.SelectedItem.value;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)