Wednesday, 30 November 2016

Bind dropdown control in asp.net c# from database

protected void bind_servicestype()
    {

        try
        {
            // bind dropdown from database
            string query="select Deposit_Type from Add_Deposit_Type";
            DataSet ds = connection.dataadapter(query);
            DropDownList1.DataSource = ds.Tables[0];
            DropDownList1.DataTextField = "Deposit_Type";
            DropDownList1.DataValueField = "Deposit_Type";
            DropDownList1.DataBind();
          
            // insert a default value in the dropdown
            DropDownList1.Items.Insert(0, new ListItem("---------Select--------", "0"));
        }
        catch (Exception EXP)
        {
            Response.Write(EXP.Message);
        }

No comments:

Post a Comment