Help with first time Dropdownlist from database.http://forums.asp.net/t/1779090.aspx/1?Help+with+first+time+Dropdownlist+from+database+Tue, 20 Mar 2012 04:05:54 -040017790904874091http://forums.asp.net/p/1779090/4874091.aspx/1?Help+with+first+time+Dropdownlist+from+database+Help with first time Dropdownlist from database. <p>Hi All, I have a thread working now that consist of all I need to help build a web page that I am converting from Classic ASP to .Net C#.&nbsp; I am very new to programming and VS 2010 C#.</p> <p>My need is to fill a Dropdownlist from items in a sql 2005 Database.</p> <p></p> <p>&nbsp;DB Table -&nbsp; Listoptions - Table</p> <p>Column1 = STable (This refers to a Table within the Database, i.e - Server, ServerCheck,Administrative,Network)</p> <p>Column2 = SColumn (This refers to a specific Column within a table, i.e. - Server_name, server_owner, software_version,device_function)</p> <p>Column3-column23 = Options1-Option21 (Here is where we add items that will appear in the dropdownlist, listitem)</p> <p>So if in the sql query, it would be to populate information regarding what the Device Function would be, i would have a statement:</p> <p><strong>select * from listoptions where stable = 'server' and scolumn = 'device_function'</strong></p> <p>Then starting with the 3 column, I would use those to fill my listitem option.&nbsp; I also need to make sure if the column is NULL, that is not added.&nbsp; That way there are no blanks in the dropdownlist.</p> <p>&nbsp;</p> <p>Again, Im new to C# and VS 2010, so any and all help with the code behind and aspx code is greatly appreciated.</p> <p>&nbsp;</p> <p>Thanks,</p> 2012-03-11T20:54:49-04:004874254http://forums.asp.net/p/1779090/4874254.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>Hi,</p> <p>As I understand you wish to fatch the data from the database and want to pop up on the drop downlist for that follow the below procedure:</p> <p>1:- stablish the connection with the connection string</p> <p>like&nbsp;</p> <p>SqlConnection conn = new SqlConnection(&quot;Data Source=ADOBE1-PC\\SQLEXPRESS; Initial Catalog=emp_details; Integrated Security=True&quot;);<br> conn.Open();<br> SqlCommand cmd = new SqlCommand();<br> cmd.Connection = conn;</p> <p>cmd.CommandType = CommandType.Text;<br> cmd.CommandText = (&quot;select columnname from tablename '&quot;);</p> <p>&nbsp; SqlDataReader adr = cmd.ExecuteReader();</p> <p>drowdownlist1.datasource=adr;</p> <p>dropdownlist1.datafield=&quot;columnname&quot;;</p> <p>dropdownlist1.databind();</p> <p>conn.close();</p> <p>once you are done with this coding you will be able &nbsp;to fatch the data from database to the dropdownlist&nbsp;</p> <p>once done let me know</p> 2012-03-12T03:13:56-04:004874466http://forums.asp.net/p/1779090/4874466.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <pre class="prettyprint">SqlConnection sqlcon = new SqlConnection(&quot;Data Source=ServerName\\SQLEXPRESS; Initial Catalog=DataBaseName; Integrated Security=True&quot;); sqlcon.Open(); SqlCommand cmd = new SqlCommand(&quot;select columnname from tablename&quot;); SqlDataReader dr = cmd.ExecuteReader(); While(dr.read()) { drowdownlist1.datasource=dr; dropdownlist1.dataTextField=&quot;columnname&quot;; dropdownlist1.dataValueField=&quot;columnnameId&quot;; dropdownlist1.DataBind(); sqlcon.close(); }</pre> 2012-03-12T05:39:25-04:004876448http://forums.asp.net/p/1779090/4876448.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>Sorry for the simple question, but the code you guys have demonstrated, does that go in the code behind in the Page Load?</p> <pre class="prettyprint">protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlcon = new SqlConnection(&quot;Data Source=ServerName\\SQLEXPRESS; Initial Catalog=DataBaseName; Integrated Security=True&quot;); sqlcon.Open(); SqlCommand cmd = new SqlCommand(&quot;select columnname from tablename&quot;); SqlDataReader dr = cmd.ExecuteReader(); While(dr.read()) { drowdownlist1.datasource=dr; dropdownlist1.dataTextField=&quot;columnname&quot;; dropdownlist1.dataValueField=&quot;columnnameId&quot;; dropdownlist1.DataBind(); sqlcon.close(); } Also, I will have about 6 different dropdownlist, will I be OK if I just have SqlCommand1 and so on as I need them depending on the exact column? I will also need to make the select query to grab everything but start on the 3 column, is there a correct way in C# to designate?</pre> 2012-03-13T02:28:32-04:004879122http://forums.asp.net/p/1779090/4879122.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <pre class="prettyprint">SqlConnection sqlcon = new SqlConnection(&quot;Data Source=ServerName\\SQLEXPRESS; Initial Catalog=DataBaseName; Integrated Security=True&quot;); protected void Page_Load(object sender, EventArgs e) { if(!IsPostback) { BindDropDown1(); BindDropDown2(); } } void BindDropDown1() { sqlcon.Open(); SqlCommand cmd = new SqlCommand(&quot;select columnname from tablename&quot;); SqlDataReader dr = cmd.ExecuteReader(); While(dr.read()) { drowdownlist1.datasource=dr; dropdownlist1.dataTextField=&quot;columnname&quot;; dropdownlist1.dataValueField=&quot;columnnameId&quot;; dropdownlist1.DataBind(); sqlcon.close(); } } void BindDropDown2() { sqlcon.Open(); SqlCommand cmd = new SqlCommand(&quot;select columnname from tablename&quot;); SqlDataReader dr = cmd.ExecuteReader(); While(dr.read()) { drowdownlist1.datasource=dr; dropdownlist1.dataTextField=&quot;columnname&quot;; dropdownlist1.dataValueField=&quot;columnnameId&quot;; dropdownlist1.DataBind(); sqlcon.close(); } }</pre> 2012-03-14T07:58:45-04:004880806http://forums.asp.net/p/1779090/4880806.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>Thank you for the response.&nbsp; I think it is starting to make a little since.&nbsp;</p> <p>I wanted to put some of my Datalist control with the dropdownlist for better understandings.&nbsp;</p> <p></p> <pre class="prettyprint">&lt;asp:DataList ID=&quot;DataList1&quot; runat=&quot;server&quot; DataKeyField=&quot;Server_Name&quot; CellPadding=&quot;4&quot; DataSourceID=&quot;SqlDataSource1&quot; onselectedindexchanged=&quot;DataList1_SelectedIndexChanged&quot; OnEditCommand=&quot;DataList1_EditCommand&quot; OnCancelCommand=&quot;DataList1_CancelCommand&quot; OnUpdateCommand=&quot;DataList1_UpdateCommand&quot;&gt; &lt;EditItemTemplate&gt; &lt;tr&gt; &lt;td&gt;Server Name:&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&lt;asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;server_name&quot;) %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;VM_Host:&lt;/td&gt;&lt;td&gt;&lt;asp:TextBox ID=&quot;txtVM_Host&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;VM_Host&quot;) %&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:LinkButton ID=&quot;LinkButton1&quot; runat=&quot;server&quot; CommandName=&quot;update&quot; &gt;Save&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&lt;asp:LinkButton CommandName=&quot;cancel&quot; ID=&quot;LinkButton2&quot; runat=&quot;server&quot;&gt;Cancel&lt;/asp:LinkButton&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Status:&lt;/td&gt;&lt;td&gt;&lt;asp:DropDownList ID=&quot;ddlStatus&quot; runat=&quot;server&quot; AppendDataBoundItems=&quot;true&quot; DataTextField='&lt;%# Eval(&quot;Status&quot;) %&gt;'&gt;&lt;asp:ListItem &gt;Select&lt;/asp:ListItem&gt;&lt;/asp:DropDownList&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:LinkButton ID=&quot;LinkButton3&quot; runat=&quot;server&quot; CommandName=&quot;update&quot; &gt;Save&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&lt;asp:LinkButton CommandName=&quot;cancel&quot; ID=&quot;LinkButton4&quot; runat=&quot;server&quot;&gt;Cancel&lt;/asp:LinkButton&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;/EditItemTemplate&gt;</pre> <p>Then the associated code behind, including your edits:</p> <p></p> <pre class="prettyprint">&lt;asp:DataList ID="DataList1" runat="server" DataKeyField="Server_Name" CellPadding="4" DataSourceID="SqlDataSource1" onselectedindexchanged="DataList1_SelectedIndexChanged" OnEditCommand="DataList1_EditCommand" OnCancelCommand="DataList1_CancelCommand" OnUpdateCommand="DataList1_UpdateCommand"&gt; &lt;EditItemTemplate&gt; &lt;tr&gt; &lt;td&gt;Server Name:&lt;/td&gt;&lt;td colspan="2"&gt;&lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Eval("server_name") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;VM_Host:&lt;/td&gt;&lt;td&gt;&lt;asp:TextBox ID="txtVM_Host" runat="server" Text='&lt;%# Eval("VM_Host") %&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:LinkButton ID="LinkButton1" runat="server" CommandName="update" &gt;Save&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&lt;asp:LinkButton CommandName="cancel" ID="LinkButton2" runat="server"&gt;Cancel&lt;/asp:LinkButton&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Status:&lt;/td&gt;&lt;td&gt;&lt;asp:DropDownList ID="ddlStatus" runat="server" AppendDataBoundItems="true" DataTextField='&lt;%# Eval("Status") %&gt;'&gt;&lt;asp:ListItem &gt;Select&lt;/asp:ListItem&gt;&lt;/asp:DropDownList&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:LinkButton ID="LinkButton3" runat="server" CommandName="update" &gt;Save&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&lt;asp:LinkButton CommandName="cancel" ID="LinkButton4" runat="server"&gt;Cancel&lt;/asp:LinkButton&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;/EditItemTemplate&gt; SqlConnection sqlcon = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\BegASPNET\\App_Data\\servers.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostback) { BindDropDown1(); } } void BindDropDown1() { sqlcon.Open(); SqlCommand cmd = new SqlCommand("select * from listoptions where stable = 'server' and scolumn = 'status'"); SqlDataReader dr = cmd.ExecuteReader(); While(dr.read()) { DataList1.DataSource = dr; DataList1.dataTextField="Status"; DataList1.dataValueField="Sever_name"; DataList1.DataBind(); sqlcon.close(); } } protected void DataList1_SelectedIndexChanged(object sender, EventArgs e) { } protected void DataList1_EditCommand(object source, DataListCommandEventArgs e) { DataList1.EditItemIndex = e.Item.ItemIndex; DataList1.DataBind(); } protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e) { DataList1.EditItemIndex = -1; DataList1.DataBind(); } protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e) { String server_name = DataList1.DataKeys[e.Item.ItemIndex].ToString(); String vm_host = ((TextBox)e.Item.FindControl("txtVM_Host")).Text; <br /> <br /> </pre> <p><br> <br> The String vm_host updates fine right now. Then I tried to add the dropdownlist and there is where I'm totally lost. Again, I'm very new so I need to test over and over to learn. The one other thing as you notice of the sqlcommand, I am selecting &quot;*&quot; from server where stable = 'server' and scolumn = 'status'. When I get the query result back, I need to make sure that the first two columns are not part of the dropdownlist. So I would skip result column1 and column2.<br> <br> Hope this helps explain it better so I can help other understand my situation.<br> <br> Thanks,<br> <br> </p> 2012-03-15T01:46:45-04:004884794http://forums.asp.net/p/1779090/4884794.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>Hello snteran</p> <p>Plz change to DataTable instead of Readerand this will reset your DataSource each time when binding</p> <pre class="prettyprint">void BindDropDown1() { using(SqlDataAdapter adapter = new SqlDataAdapter(&quot;select * from listoptions where stable = 'server' and scolumn = 'status'&quot;,&quot;Your connection string&quot;) { DataTable dt = new DataTable(); adapter.Fill(dt); DataList1.DataSource = dt; DataList1.dataTextField=&quot;Status&quot;; DataList1.dataValueField=&quot;Sever_name&quot;; DataList1.DataBind(); } }</pre> 2012-03-17T01:44:17-04:004885628http://forums.asp.net/p/1779090/4885628.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>Thank you for the suggestion, however it is still not working.&nbsp; I get a compilation error:</p> <p>CS1061: 'System.Web.UI.WebControls.DataList' does not contain a definition for 'DataTextField'</p> <p>&nbsp;</p> <p>I also have an issue with the DataValueField.</p> <p>&nbsp;</p> <p>Here is the Code behind: (I changed it a little bit, I would like to stay away from keeping the connection string in the code since I want to be able to use the same code for my Dev/Test and Prod sites)</p> <p></p> <pre class="prettyprint">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.Sql; using System.Data.SqlClient; public partial class info : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindDropDown1(); } } void BindDropDown1() { using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlDataAdapter adapter = new SqlDataAdapter(&quot;select * from listoptions where stable = 'server' and scolumn = 'status'&quot;, &quot;conn&quot;)) { DataTable dt = new DataTable(); adapter.Fill(dt); DataList1.DataSource = dt; DataList1.DataTextField = &quot;Status&quot;; DataList1.DataValueField = &quot;regStatus&quot;; DataList1.DataBind(); } } }</pre> <p><br />Now the Web.aspx page:<br /><br /></p> <pre class="prettyprint">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.Sql; using System.Data.SqlClient; public partial class info : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindDropDown1(); } } void BindDropDown1() { using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlDataAdapter adapter = new SqlDataAdapter(&quot;select * from listoptions where stable = 'server' and scolumn = 'status'&quot;, &quot;conn&quot;)) { DataTable dt = new DataTable(); adapter.Fill(dt); DataList1.DataSource = dt; DataList1.DataTextField = &quot;Status&quot;; DataList1.DataValueField = &quot;regStatus&quot;; DataList1.DataBind(); } } } &lt;asp:DataList ID="DataList1" runat="server" DataKeyField="Server_Name" CellPadding="4" DataSourceID="SqlDataSource1" onselectedindexchanged="DataList1_SelectedIndexChanged" OnEditCommand="DataList1_EditCommand" OnCancelCommand="DataList1_CancelCommand" OnUpdateCommand="DataList1_UpdateCommand"&gt; &lt;HeaderTemplate&gt; &lt;table border="1" cellpadding="5" cellspacing="0"&gt; &lt;/HeaderTemplate&gt; &lt;EditItemTemplate&gt; &lt;tr&gt; &lt;td&gt;Server Name:&lt;/td&gt;&lt;td colspan="2"&gt;&lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Eval("server_name") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;VM_Host:&lt;/td&gt;&lt;td&gt;&lt;asp:TextBox ID="txtVM_Host" runat="server" Text='&lt;%# Eval("VM_Host") %&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:LinkButton ID="LinkButton1" runat="server" CommandName="update" &gt;Save&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&lt;asp:LinkButton CommandName="cancel" ID="LinkButton2" runat="server"&gt;Cancel&lt;/asp:LinkButton&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Status:&lt;/td&gt;&lt;td&gt;&lt;asp:DropDownList ID="ddlStatus" runat="server" AppendDataBoundItems="true" DataTextField='&lt;%# Eval("Status") %&gt;' DataValueField="regStatus"&gt; &lt;asp:ListItem Text="&lt;Select Subject&gt;" Value="0" /&gt;&lt;/asp:DropDownList&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:LinkButton ID="LinkButton3" runat="server" CommandName="update" &gt;Save&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&lt;asp:LinkButton CommandName="cancel" ID="LinkButton4" runat="server"&gt;Cancel&lt;/asp:LinkButton&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/EditItemTemplate&gt; <br /><br /><br /></pre> <p>Again, I might have done this completely wrong.&nbsp; I am trying to read my textbook (Pro C# 2008 and the .Net 3.5 Platform, search the web and use this forum to build my new ASP.Net site)</p> <p>&nbsp;</p> <p>Thanks for the help,</p> 2012-03-17T22:40:41-04:004885766http://forums.asp.net/p/1779090/4885766.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>Hello snteran</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>snteran</h4> <span class="kwd">void</span><span class="pln"> </span><span class="typ">BindDropDown1</span><span class="pun">()</span></blockquote> <p></p> <p>Of course DataList hasn't DataTextField and DataValueFieldBut why do you name binding a DataList as a &quot;BindDropDown&quot; I thought it was binding to a Dropdownlist</p> <p>Plz change from &quot;DataList&quot; to &quot;Dropdownlist&quot; and have a try</p> 2012-03-18T00:42:38-04:004885804http://forums.asp.net/p/1779090/4885804.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>Hello Decker,</p> <p>&nbsp;</p> <p>I appreciate your assistance.&nbsp; I apologize if Im not explaining myself very well.&nbsp; I guess Im still at the point of I dont know, what I dont know to ask good questions.</p> <p>&nbsp;</p> <p>As the title states, I need help creating a Dropdownlist that is populated from a Database table.&nbsp; The table holds many types of option list, it depends what the first two columns hold as to what the remainder of the columns will hold.&nbsp; I have the setup of the table in my opening question(as to not repeat it again).</p> <p>&nbsp;</p> <p>I dont understand, replace datalist with dropdownlist?&nbsp; I dont see datalist being used in the code behind.&nbsp; I tried to replace the DataTable to a Dropdownlist but that did not work either.&nbsp;</p> <p>&nbsp;</p> <p>Again, I apologize for the silly questions and not understanding your request, but Im very new to this process and need all the help I can get.</p> <p>&nbsp;</p> <p>Thanks,</p> 2012-03-18T01:51:03-04:004885805http://forums.asp.net/p/1779090/4885805.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>Hello again</p> <p>I don't understandeitherSince you are dealling with Dropdownlistand what does it have any relationship with Dropdownlist</p> <p>Reguards and Thanks</p> 2012-03-18T01:55:10-04:004888526http://forums.asp.net/p/1779090/4888526.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>OK, so I'm still trying to get what I would think would be a simple step done in C#/aspx.</p> <p></p> <p>My aspx Edittemplate:</p> <pre class="prettyprint">&lt;EditItemTemplate&gt; &lt;tr&gt; &lt;td&gt;Server Name:&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&lt;asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;server_name&quot;) %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;VM_Host:&lt;/td&gt;&lt;td&gt;&lt;asp:TextBox ID=&quot;txtVM_Host&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;VM_Host&quot;) %&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:LinkButton ID=&quot;LinkButton1&quot; runat=&quot;server&quot; CommandName=&quot;update&quot; &gt;Save&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&lt;asp:LinkButton CommandName=&quot;cancel&quot; ID=&quot;LinkButton2&quot; runat=&quot;server&quot;&gt;Cancel&lt;/asp:LinkButton&gt;&lt;/td&gt; &lt;/tr&gt; &lt;td&gt; &lt;asp:DropDownList ID=&quot;ddlStatus&quot; runat=&quot;server&quot; DataSourceID=&quot;SqlDataSource1&quot; DataTextField=&quot;Status&quot; DataValueField=&quot;Status&quot; SelectedValue='&lt;%# Bind(&quot;Status&quot;) %&gt;' AppendDataBoundItems=&quot;True&quot;&gt; &lt;/asp:DropDownList&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:LinkButton ID=&quot;LinkButton3&quot; runat=&quot;server&quot; CommandName=&quot;update&quot; &gt;Save&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&lt;asp:LinkButton CommandName=&quot;cancel&quot; ID=&quot;LinkButton4&quot; runat=&quot;server&quot;&gt;Cancel&lt;/asp:LinkButton&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/EditItemTemplate&gt;</pre> <p><br />As you can see in the EditItemTemplate, the dropdownlist control is added and needs to show up as one of the edit items with a populated dropdownlist.</p> <p><br />Here is the code behind:<br /><br /></p> <pre class="prettyprint"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindDropDown1(); } } private void BindDropDown1() { SqlConnection cs = new SqlConnection(ConfigurationManager.ConnectionStrings["sCheckEDConnectionString"].ToString()); string query = "select * from wwwlistoptions where stable = 'server' and scolumn = 'status'"; SqlDataAdapter da = new SqlDataAdapter(query, cs); DataSet ds = new DataSet(); da.Fill(ds, "status"); DataTable dt = new DataTable(); da.Fill(dt); for (int i = 0; i &lt; dt.Rows.Count; i++) { Code Needed? } } </pre> <p>I have been looking through the net to find a method to process my update. I hope I can get some help so I can move forward. Thanks,</p> <p></p> 2012-03-20T03:32:16-04:004888568http://forums.asp.net/p/1779090/4888568.aspx/1?Re+Help+with+first+time+Dropdownlist+from+database+Re: Help with first time Dropdownlist from database. <p>Hello</p> <p>Since you are using a Dropdownlist inside the DataListyou should change your UI to design modethen choose the &quot;EditTemplate&quot; and then directly bind the Dropdownlist with the DataSourceset DataTextField and DataValueField and set SelectedValue to itMake sure that your SelectedValue must be one of the items bound to the Dropdownlist as a datasourceor error will be thrown out</p> <p>Reguards</p> 2012-03-20T04:05:54-04:00