Using asp.net, I have a form with a dropdownlist that is populated onload. I do this by binding to a datareapter. My first question is how can I add value and text to the dropdown with binding. I see you can do this by ListItem.Value but is there an easy solution?

My other issue is that my value that comes back is always the first item in my list?

Need some help.

VB Code:
  1. <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Trace="false" debug="true"%>
  2. <%@ import Namespace="System.Data.SqlClient" %>
  3. <%@ Import Namespace="System.Data" %>
  4. <%@ Import Namespace="System.IO" %>
  5.  
  6. <script runat="server">
  7.  
  8.     Sub Add_Info(s As Object, e as EventArgs)
  9.         lblMsg.Text = drpManufacturer.SelectedValue
  10.     End Sub
  11.    
  12.     Sub Page_Load
  13.    
  14.             Dim conPubs as SqlConnection
  15.             Dim cmdSQL as SqlCommand
  16.             Dim dtrAllProducts as SqlDataReader
  17.            
  18.             'Retrieve records from database
  19.             conPubs = New SqlConnection("Server=xx.xx.xx.xx;uid=name;pwd=pwd;database=db")
  20.             cmdSQL = New SqlCommand("SELECT * FROM why3s_products", conPubs)
  21.             conPubs.Open()
  22.             dtrAllProducts = cmdSQL.ExecuteReader()
  23.                        
  24.             'Bind to Repeater
  25.             rptPrdList.DataSource = dtrAllProducts
  26.             rptPrdList.DataBind()
  27.                        
  28.             dtrAllProducts.Close()
  29.             conPubs.Close()
  30.  
  31.             'Retrieve records from database
  32.             conPubs = New SqlConnection("Server=xx.xx.xx.xx;uid=name;pwd=pwd;database=db")
  33.             cmdSQL = New SqlCommand("SELECT manufacturers_name FROM why3s_manufacturers", conPubs)
  34.             conPubs.Open()
  35.             dtrAllProducts = cmdSQL.ExecuteReader()
  36.                                    
  37.             'Bind to DropDownList
  38.             drpManufacturer.DataSource = dtrAllProducts
  39.             drpManufacturer.DataTextField = "manufacturers_name"
  40.             drpManufacturer.DataBind()
  41.            
  42.             dtrAllProducts.Close()
  43.             conPubs.Close()
  44.     End Sub
  45.  
  46. </script>
  47. <html>
  48. <head>
  49.     <title>Add New Manufacturer</title>
  50.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  51. </head>
  52. <body>
  53.     <form id="frmAdd" name="frmAdd" action="addproduct.aspx" method="post" enctype="multipart/form-data" runat="server">
  54.     <!--#include file="inc_top_menu.aspx" --><br>
  55.  
  56.         <table cellspacing="0" cellpadding="0" width="750" border="0">
  57.             <tbody>
  58.                 <tr>
  59.                    
  60.         <td width="125" valign="top"> <asp:validationsummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" HeaderText="Missing:" DisplayMode="List"></asp:validationsummary>
  61.         </td>
  62.                     <td width="625">
  63.                         <table cellspacing="2" cellpadding="0" width="100%" border="0">
  64.             <tbody>
  65.              <tr>
  66.                 <td>Manufacturer:</td>
  67.                 <td><asp:dropdownlist ID="drpManufacturer" runat="server"></asp:dropdownlist>
  68.                   - <em><font size="2" face="Verdana, Arial, Helvetica, sans-serif">If
  69.                   not in list please create before you continue.</font></em></td>
  70.               </tr>
  71.               <tr>
  72.                 <td width="26%"> Product Model Name:</td>
  73.                 <td width="74%"> <asp:textbox id="txtModel" runat="server" TextMode="SingleLine" MaxLength="15"></asp:textbox> <asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" Text="Required" ErrorMessage="Model Name" ControlToValidate="txtModel"></asp:requiredfieldvalidator> </td>
  74.               </tr>
  75.               <tr>
  76.                 <td>Product Fullmodel Name:</td>
  77.                 <td><asp:textbox AutoPostBack="false" ID="txtFullModel" MaxLength="60" runat="server" /> <asp:requiredfieldvalidator ControlToValidate="txtFullModel" ErrorMessage="Fullmodel Name" Text="Required" runat="server" /> </td>
  78.               </tr>
  79.               <tr>
  80.                 <td> Product Image:</td>
  81.                 <td><input name="inpFileUpload" type="file" id="inpFileUpload" size="40" maxlength="60"  Runat="Server">
  82.                   <font size="1" face="Verdana, Arial, Helvetica, sans-serif"><em>300kb
  83.                   max file size.</em></font></td>
  84.               </tr>
  85.               <tr>
  86.                 <td> Product Description</td>
  87.                 <td> <asp:textbox id="txtDescription" runat="server" TextMode="SingleLine" MaxLength="255" Columns="50"></asp:textbox> <asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server" Text="Required" ErrorMessage="Description" ControlToValidate="txtDescription"></asp:requiredfieldvalidator> </td>
  88.               </tr>
  89.               <tr>
  90.                 <td>Product Price:</td>
  91.                 <td><asp:textbox ID="txtPrice" MaxLength="10" runat="server" /> <asp:requiredfieldvalidator ControlToValidate="txtPrice" ErrorMessage="Price" InitialValue="Required" runat="server" Text="Required" /> </td>
  92.               </tr>
  93.               <tr>
  94.                 <td>Product Retail Price:</td>
  95.                 <td><asp:textbox ID="txtRetail" MaxLength="10" runat="server" /></td>
  96.               </tr>
  97.               <tr>
  98.                 <td>Product Cost:</td>
  99.                 <td><asp:textbox ID="txtCost" MaxLength="10" runat="server" /></td>
  100.               </tr>
  101.               <tr>
  102.                 <td>Product Wholesale Price:</td>
  103.                 <td><asp:textbox ID="txtWholesale" MaxLength="10" runat="server" /></td>
  104.               </tr>
  105.               <tr>
  106.                 <td>Product Weight:</td>
  107.                 <td><asp:textbox ID="txtWeight" MaxLength="7" runat="server" /></td>
  108.               </tr>
  109.               <tr>
  110.                 <td>Product Status:</td>
  111.                 <td><div align="left">
  112.                     <asp:dropdownlist ID="drpStatus" runat="server">
  113.                     <asp:listitem Text="Show" runat="server"></asp:listitem>
  114.                     <asp:listitem Text="Hide" runat="server"></asp:listitem>
  115.                     </asp:dropdownlist>
  116.                     <em><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Display
  117.                     vacuum on page.</font></em></div></td>
  118.               </tr>
  119.               <tr>
  120.                 <td>Product Sold-To-Dt:</td>
  121.                 <td><asp:textbox ID="txtSTD" MaxLength="4" runat="server" Text="0" /> <asp:requiredfieldvalidator ControlToValidate="txtSTD" ErrorMessage="Sold-To-Date" InitialValue="Required" Text="Required" runat="server" /> </td>
  122.               </tr>
  123.               <tr>
  124.                 <td>Product Show Button:</td>
  125.                 <td><asp:dropdownlist ID="drpShowBuy" runat="server">
  126.                     <asp:listitem Text="Show" runat="server"></asp:listitem>
  127.                     <asp:listitem Text="Hide" runat="server"></asp:listitem>
  128.                     </asp:dropdownlist> <em><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Do
  129.                   not display the buy button.</font></em></td>
  130.               </tr>
  131.               <tr>
  132.                 <td>Product Special Notify:</td>
  133.                 <td><asp:textbox ID="txtSpecialNotify" MaxLength="55" runat="server" /></td>
  134.               </tr>
  135.                <tr>
  136.                 <td>Product Quantity:</td>
  137.                 <td><asp:textbox ID="txtQuantity" MaxLength="4" runat="server" Text="0" /></td>
  138.               </tr>
  139.               <tr>
  140.                 <td>&nbsp;</td>
  141.                 <td><asp:button ID="butAdd" OnClick="Add_Info" runat="server" Text="Add" BackColor="Yellow" BorderColor="Blue" BorderStyle="Groove"></asp:button> <asp:label ID="lblError" runat="server"></asp:label></td>
  142.               </tr>
  143.               <tr>
  144.                 <td>&nbsp;</td>
  145.                 <td><asp:label ID="lblMsg" runat="server"></asp:label></td>
  146.               </tr>
  147.              
  148.             </tbody>
  149.           </table>
  150.                     </td>
  151.                 </tr>
  152.             </tbody>
  153.         </table>
  154.         </form>
  155.     <br />
  156.     <center>
  157.     <asp:repeater EnableViewState="false" ID="rptPrdList" runat="server">
  158.         <headertemplate>
  159.             <table border="1">
  160.                 <tr>
  161.                     <th>ID</th>
  162.                     <th>Name</th>
  163.                     <th>Image</th>
  164.                     <th>Entry_Dt</th>
  165.                     <th>Description</th>
  166.                 </tr>
  167.         </headertemplate>
  168.        
  169.         <itemtemplate>
  170.             <tr bgcolor="#CCFFFF">
  171.                
  172.           <td><a href="updatemanufacturer.aspx?ID=<%# Container.DataItem("manufacturers_id") %>"><%# Container.DataItem("manufacturers_id") %></a></td>
  173.                 <td><%# Container.DataItem("manufacturers_name") %></td>
  174.                 <td><%# Container.DataItem("manufacturers_image") %></td>
  175.                 <td><%# Container.DataItem("manufacturers_entry_dt") %></td>
  176.                 <td><%# Container.DataItem("manufacturers_description") %></td>
  177.             </tr>
  178.         </itemtemplate>
  179.        
  180.         <AlternatingItemTemplate>
  181.             <tr bgcolor="#99FF66">
  182.                 <td><%# Container.DataItem("manufacturers_id") %></td>
  183.                 <td><%# Container.DataItem("manufacturers_name") %></td>
  184.                 <td><%# Container.DataItem("manufacturers_image") %></td>
  185.                 <td><%# Container.DataItem("manufacturers_entry_dt") %></td>
  186.                 <td><%# Container.DataItem("manufacturers_description") %></td>
  187.             </tr>
  188.         </AlternatingItemTemplate>
  189.        
  190.         <footertemplate>
  191.             </table>
  192.         </footertemplate>
  193.     </asp:repeater>
  194.     </center>
  195. </body>
  196. </html>