Dropdown list binding using class method RRS feed

  • Question

  • User-1763739080 posted

    Dropdown list binding using class methode

    in class file i have written this code

    public DataSet companyshow()
    using (SqlConnection connection = new SqlConnection(GetConnectionString()))
    SqlCommand cmd = new SqlCommand("OrderProduct1;", connection);
    cmd.CommandType = CommandType.StoredProcedure;
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    catch (Exception ex)
    //write error message
    return ds; 


    and on page load code is

    protected void Page_Load(object sender, EventArgs e)

    ordercls oc = new ordercls();

    ddlCompany.DataSource = oc.companyshow();

    but i am getting this error > The IListSource does not contain any data sources.

    any help will be apperiaciated !!!

    Wednesday, August 22, 2018 7:37 PM

All replies

  • User632428103 posted

    Hello and welcome to asp net

    i think you need to add a if(!IsPostBack) on page load as this :

    protected void Page_Load(object sender, EventArgs e)
                if (!IsPostBack)

    and place your code ...

    the IsPostBack == false check if the page IS NOT SEND to the server

    if it's not working, check the store procedure if it's returned some data ...

    If yes try perhpas to assign datas as this :

    DataSet ds = oc.companyshow(); // check value
    yourDropDown.datasource = ds.Tables[0]; // assign datas (first table) to your drop down

    Thursday, August 23, 2018 7:01 AM
  • User-893317190 posted

    Hi androiduser ,

    It is most possible that your DataSet has no data in it.

    I have run the code below.

      DropDownList1.DataSource =new DataSet();

    And meet the same problem as yours.

    Please check your StoredProcedure to see whether it returns data.

    Best regards,

    Ackerly Xu

    Friday, August 24, 2018 7:42 AM