Databind a dropdownlist

前端 未结 4 2047
梦毁少年i
梦毁少年i 2020-12-03 18:39

When I try to databing dropdownlist, got this: system.data.datarowview
what do I wrong?

 string strQuery = \"Select Item FROM         


        
4条回答
  •  误落风尘
    2020-12-03 19:33

    string strQuery = "Select Item FROM Calendar Where UserD='Test'";
    

    Note you need to use single quotations around the string, as in your code you didn't finish the inital string ever, so the rest of the code just became part of strQuery.

    In addition if you bring back more than one field in the future, when you bind a dropdown list you need to specify which field from the database is the value and which is the displayed text.

    ddlList.DataSource = sqlTa;
    ddlList.DataValueField = "ValueFieldFromDatabaseResults";
    ddlList.DataTextField = "ShownTextFieldFromDatabaseResults";
    ddlList.DataBind();
    

提交回复
热议问题