Drop Down List Important Points

1)Select Default value
     ddlusers.Items.FindByText("Rohini").Selected = True

2)Select Values from dropdown list
    lblResult.Text = DropdownList1.SelectedValue;

3)Select default valut as "select item"
   ddlCountry.Items.Insert(0,new ListItem("------Select Item -----"));

4) Example

protected void GetValue(object sender, EventArgs e)
{
    //Reference the Repeater Item using Button.
    RepeaterItem item = (sender as Button).NamingContainer as RepeaterItem;
    //Reference the DropDownList.
    DropDownList ddlCountries = item.FindControl("ddlCountries"as DropDownList;
    //Get the Selected Text.
    string selectedText = ddlCountries.SelectedItem.Text;
    //Get the Selected Value.
    string selectedValue = ddlCountries.SelectedItem.Value;
    string message = string.Format("Selected Text: {0} Selected Value: {1}", selectedText, selectedValue);
    ClientScript.RegisterStartupScript(this.GetType(), "alert""alert('" + message + "');"true);
}

Previous Post Next Post