{"push_id":571490527,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"40133741335117786557d507cc76c54e1dc4b7b4","before":"e06e18a632074e43807a74e0588ea13c685744ff","commits":[{"sha":"40133741335117786557d507cc76c54e1dc4b7b4","author":{"email":"46bdae3e72dc39de84d1ff2018271642d0799a03@yahoo.com","name":"amankhatri"},"message":"setting default value of dropdownlist add elements\n\nDropDownList is a listItem Collection object\n/*Every item in the list has a id associated with list item, */\n\nwebform1.aspx HTML\n<asp:DropDownList ID=\"DropDownList1\" runat=\"server\"\nonselectedindexchanged=\"DropDownList1_SelectedIndexChanged\">\n<asp:ListItem Text=\"Select Continent\" Value= \"-1\"></asp:ListItem> //id =\n0\n<!--<asp:ListItem Text=\"Asia\" Selected=\"True\" Value =\n\"1\"></asp:ListItem> --> //setting default value in list\n<asp:ListItem Text=\"Asia\" Value = \"1\"></asp:ListItem> //Id = 1\n<asp:ListItem Text=\"Europe\" Value = \"2\"></asp:ListItem>\n<asp:ListItem Text=\"Africa\" Value = \"3\"></asp:ListItem>\n<asp:ListItem Text=\"North America\" Value = \"4\"></asp:ListItem>\n<asp:ListItem Text=\"South America\" Value = \"5\"></asp:ListItem>\n\n</asp:DropDownList>\n\nTo retrieve :\nSelected Item Text: DropDownList1.Selectedtem.Text\nSelected Item Value: DropDownList1.SelectedItem.Value\nOR\nSelected Item Value: DropDownList1.SelectedValue\nSelected Item Index: DropDownList1.SelectedIndex\n\nThe SelectedIndex and SelectedValue properties of the DropDownList can\nalso be used to have a list item selected in the DropDownList.\n\nprotected void Page_Load(object sender, EventArgs e)\n{\nif (!IsPostBack)\n{\n/*Default Selection in dropdownLIst. The default collection should\nalways occur in if condition\nbecause if it is a post back it will again display the same condition*/\nDropDownList1.SelectedIndex = 1;\n/*or you can do DropDownList1.SelectedValue = \"1\"*/\n}\n\n}\n\nprotected void DropDownList1_SelectedIndexChanged(object sender,\nEventArgs e)\n{\n\n}\n\nprotected void Button1_Click(object sender, EventArgs e)\n{\nif (DropDownList1.SelectedValue == \"-1\")\n{\nResponse.Write(\"Please Make a selection\");\n}\nelse{\nResponse.Write(\"Text \" + DropDownList1.SelectedItem.Text+ \" <br/>\");\nResponse.Write(\"Value \" + DropDownList1.SelectedItem.Value+ \" <br/>\");\nResponse.Write(\"ID or Index \" + DropDownList1.SelectedIndex+ \" <br/>\");\n\n}\n\n}\n}","distinct":true,"url":"https://api.github.com/repos/amankhatri/ASP-DOT-NET/commits/40133741335117786557d507cc76c54e1dc4b7b4"}]}