private void bindtoddl()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings[""].ToString();
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select 'S'+Cast(stateID as varchar)stateID ,CountryID,StateName from [States] UNION Select 'C'+Cast(countryID as varchar)Countryid , CountryID as CountryID,CountryName from Countries order by CountryID,stateID", conn);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "StateName";
DropDownList1.DataValueField = "CountryID";
DropDownList1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
foreach (var item in DropDownList1.Items.Cast<ListItem>().Where(li => li.Value.StartsWith("C", StringComparison.OrdinalIgnoreCase)))
{
item.Attributes.CssStyle.Add("style", "font-weight:bold");
}
This is my code,Please Check it
bindtoddl();
}
}
page load
vijaya
Vijayar, if this helps please login to Mark As Answer. | Alert Moderator