Note that there are some explanatory texts on larger screens.

plurals
  1. PObinding a dropdownlist to a database
    primarykey
    data
    text
    <p>I want to bind a dropdownlist to a database. I did the following coding but it isn't working.</p> <pre><code>using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.Odbc; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { rebind(); } } public void rebind() { try { OdbcConnection myConn = new OdbcConnection(ConfigurationManager.ConnectionStrings["myconn"].ConnectionString); string sql = "select casename,casecode from casetype"; myConn.Open(); OdbcCommand cmd = new OdbcCommand(sql, myConn); OdbcDataReader MyReader = cmd.ExecuteReader(); { DropDownList3.DataSource= sql; DropDownList3.DataTextField = "casename"; DropDownList3.DataValueField = "casetype"; DropDownList3.DataBind(); } } catch (Exception ex) { Response.Write(ex.StackTrace); } } } </code></pre> <p>I am getting the error as</p> <pre><code>at _Default.rebind() in c:\Documents and Settings\a\My Documents\Visual Studio 2008\WebSites\toolbar1\Default.aspx.cs:line 32 </code></pre> <p>Please help me to solve my problem and bind the dropdownlist to a datasource.I want my dropdownlist to display text from a database column and use the value field for some other purpose later on in code. I am getting the page displayed when i run the project but not able to get the data in dropdownlist</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload