Showing posts with label binding. Show all posts
Showing posts with label binding. Show all posts

Wednesday, March 28, 2012

Trouble binding a dropdown list in a detailsview.

Hi

On 17 Nov, 01:37, B. Chernick wrote:

Quote:

Originally Posted by

Sorry, actually no. If I move the code into the DetailView's DataBinding
event (or the screen's), the code fails entirely because it can't find the
ddl. Hasn't been rendered yet.


Milosz is right about the timing of the code causing the exception. In
insert mode, there is no attempt to automatically bind the selected
value of the ddl control to a field value because it's a new record,
whereas in Edit mode it tries to bind the selected value to the
current value of the field.

To get round this you'll have to delete the databinding between the
ddl and the datasource (in the edit mode template) and set the
selected value manually in code immediately after the code you have
already written. In the DataBound event, you can differentiate
betweeen the two modes using DetailsView1.CurrentMode() and make the
code for setting the ddl selected value conditonal upon that.

You'll also need to handle the update manually for the respective
datafield as well in the Updating event.

HTHThank you Milosz and Phil.

Out of town for the holiday but I continue this as soon as I get home Friday.

"Phil H" wrote:

Quote:

Originally Posted by

Hi
>
On 17 Nov, 01:37, B. Chernick wrote:

Quote:

Originally Posted by

Sorry, actually no. If I move the code into the DetailView's DataBinding
event (or the screen's), the code fails entirely because it can't find the
ddl. Hasn't been rendered yet.


>
Milosz is right about the timing of the code causing the exception. In
insert mode, there is no attempt to automatically bind the selected
value of the ddl control to a field value because it's a new record,
whereas in Edit mode it tries to bind the selected value to the
current value of the field.
>
To get round this you'll have to delete the databinding between the
ddl and the datasource (in the edit mode template) and set the
selected value manually in code immediately after the code you have
already written. In the DataBound event, you can differentiate
betweeen the two modes using DetailsView1.CurrentMode() and make the
code for setting the ddl selected value conditonal upon that.
>
You'll also need to handle the update manually for the respective
datafield as well in the Updating event.
>
HTH
>

Trouble binding a dropdown list in a detailsview.

Ok, I'm lost. I'm writing a webpage in VB/Dot Net 2.0 and I'm trying to put
a
dropdown list in a detailsview. The dropdownlist is supposed to display a
simple enum.
From what little I've seen so far, the place in VB code to bind a ddl is in
the detailview's databound event. Any earlier and you can't get a handle on
the ddl. The detailsview is essentially alone on it's page and is called in
either edit or insert mode only. (In the page lode, I examine a querystring
parameter and based on that, set the detailsview to either edit or insert
mode.) I have created template ddls in the column corresponding to this
variable. All existing records have valid values in this field (a smallint)
.
The code itself is routine:
ddlClassType = DetailsView1.FindControl("ddlClassType")
Dim names() As String = System.Enum.GetNames(GetType(ClassType))
Dim values() As Integer = System.Enum.GetValues(GetType(ClassType))
Dim i As Integer
For i = 0 To names.Length - 1
Dim item As New ListItem(names(i), values(i).ToString)
ddlClassType.Items.Add(item)
Next
This works fine for Inserts but the code never gets to this point for
updates. It crashes with the error: 'ddlClassType' has a SelectedValue whic
h
is invalid because it does not exist in the list of items. Parameter name:
value
Any suggestions?Howdy,
Moving population code into detail's DataBinding event should resolve the
problem. Take a look at your aspx code and notice, there's Bind or Eval
statement inside SelectedValue: SelectedValue='<%# Eval("WhatEver") %>' whic
h
expects items have already been populated. Unfortunatelly, you're populating
items afterwards, hence the exception.
hope this helps
--
Milosz
"B. Chernick" wrote:

> Ok, I'm lost. I'm writing a webpage in VB/Dot Net 2.0 and I'm trying to pu
t a
> dropdown list in a detailsview. The dropdownlist is supposed to display a
> simple enum.
> From what little I've seen so far, the place in VB code to bind a ddl is i
n
> the detailview's databound event. Any earlier and you can't get a handle
on
> the ddl. The detailsview is essentially alone on it's page and is called
in
> either edit or insert mode only. (In the page lode, I examine a querystrin
g
> parameter and based on that, set the detailsview to either edit or insert
> mode.) I have created template ddls in the column corresponding to this
> variable. All existing records have valid values in this field (a smallin
t).
>
> The code itself is routine:
> ddlClassType = DetailsView1.FindControl("ddlClassType")
> Dim names() As String = System.Enum.GetNames(GetType(ClassType))
> Dim values() As Integer = System.Enum.GetValues(GetType(ClassType))
> Dim i As Integer
> For i = 0 To names.Length - 1
> Dim item As New ListItem(names(i), values(i).ToString)
> ddlClassType.Items.Add(item)
> Next
> This works fine for Inserts but the code never gets to this point for
> updates. It crashes with the error: 'ddlClassType' has a SelectedValue wh
ich
> is invalid because it does not exist in the list of items. Parameter name:
> value
> Any suggestions?
>
Sorry, actually no. If I move the code into the DetailView's DataBinding
event (or the screen's), the code fails entirely because it can't find the
ddl. Hasn't been rendered yet.
I have a vague memory of populating a dropdown in my last job using
javascript and those <%# %> brackets, but I'm still digging through my notes
for that one. Have you ever done that?
"Milosz Skalecki [MCAD]" wrote:
> Howdy,
> Moving population code into detail's DataBinding event should resolve the
> problem. Take a look at your aspx code and notice, there's Bind or Eval
> statement inside SelectedValue: SelectedValue='<%# Eval("WhatEver") %>' wh
ich
> expects items have already been populated. Unfortunatelly, you're populati
ng
> items afterwards, hence the exception.
> hope this helps
> --
> Milosz
>
> "B. Chernick" wrote:
>
Many times. Paste the code.
--
Milosz
"B. Chernick" wrote:
> Sorry, actually no. If I move the code into the DetailView's DataBinding
> event (or the screen's), the code fails entirely because it can't find the
> ddl. Hasn't been rendered yet.
> I have a vague memory of populating a dropdown in my last job using
> javascript and those <%# %> brackets, but I'm still digging through my not
es
> for that one. Have you ever done that?
> "Milosz Skalecki [MCAD]" wrote:
>
Hi
On 17 Nov, 01:37, B. Chernick wrote:
> Sorry, actually no. If I move the code into the DetailView's DataBinding
> event (or the screen's), the code fails entirely because it can't find the
> ddl. Hasn't been rendered yet.
Milosz is right about the timing of the code causing the exception. In
insert mode, there is no attempt to automatically bind the selected
value of the ddl control to a field value because it's a new record,
whereas in Edit mode it tries to bind the selected value to the
current value of the field.
To get round this you'll have to delete the databinding between the
ddl and the datasource (in the edit mode template) and set the
selected value manually in code immediately after the code you have
already written. In the DataBound event, you can differentiate
betweeen the two modes using DetailsView1.CurrentMode() and make the
code for setting the ddl selected value conditonal upon that.
You'll also need to handle the update manually for the respective
datafield as well in the Updating event.
HTH
Thank you Milosz and Phil.
Out of town for the holiday but I continue this as soon as I get home Friday
.
"Phil H" wrote:

> Hi
> On 17 Nov, 01:37, B. Chernick wrote:
> Milosz is right about the timing of the code causing the exception. In
> insert mode, there is no attempt to automatically bind the selected
> value of the ddl control to a field value because it's a new record,
> whereas in Edit mode it tries to bind the selected value to the
> current value of the field.
> To get round this you'll have to delete the databinding between the
> ddl and the datasource (in the edit mode template) and set the
> selected value manually in code immediately after the code you have
> already written. In the DataBound event, you can differentiate
> betweeen the two modes using DetailsView1.CurrentMode() and make the
> code for setting the ddl selected value conditonal upon that.
> You'll also need to handle the update manually for the respective
> datafield as well in the Updating event.
> HTH
>
After some trial and error, I finally got it to work. Is this roughly what
you had in mind? (I first replaced the ddl in the edit template with a new
unbound dropdownlist.)
Private Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
Dim names() As String = System.Enum.GetNames(GetType(ClassType))
Dim values() As Integer = System.Enum.GetValues(GetType(ClassType))
If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
ddlClassType = DetailsView1.FindControl("ddlClassType")
Dim i As Integer
For i = 0 To names.Length - 1
Dim item As New ListItem(names(i), values(i).ToString)
ddlClassType.Items.Add(item)
Next
' Set incoming value
Dim dr As DataRowView
dr = DetailsView1.DataItem
ddlClassType.SelectedValue = dr.Item("ClassType").ToString
End If
End Sub
Private Sub ObjectDataSource1_Updating(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles
ObjectDataSource1.Updating
' manually update values here
ddlClassType = DetailsView1.FindControl("ddlClassType")
e.InputParameters.Item("ClassType") = ddlClassType.SelectedValue
End Sub
"Phil H" wrote:

> Hi
> On 17 Nov, 01:37, B. Chernick wrote:
> Milosz is right about the timing of the code causing the exception. In
> insert mode, there is no attempt to automatically bind the selected
> value of the ddl control to a field value because it's a new record,
> whereas in Edit mode it tries to bind the selected value to the
> current value of the field.
> To get round this you'll have to delete the databinding between the
> ddl and the datasource (in the edit mode template) and set the
> selected value manually in code immediately after the code you have
> already written. In the DataBound event, you can differentiate
> betweeen the two modes using DetailsView1.CurrentMode() and make the
> code for setting the ddl selected value conditonal upon that.
> You'll also need to handle the update manually for the respective
> datafield as well in the Updating event.
> HTH
>

trouble binding a datagrid to a custom collection

I'm trying to bind a custom collection to an autogenerated datagrid without
success.
I'm getting this error:
DataGrid with id 'DataGrid2' could not automatically generate any columns
from the selected data source.
Could you help me to find a solution? What is the problem in my code? Thanks
.
Here is my code (NewsContent.aspx):
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
</form>
//----
Code behind:(NewsContent.aspx.cs).
public class NewsContent{
private void Page_Load(object sender, System.EventArgs e)
{
ListItemCollection myListCollection = AddToCustomCollection();
this.DataGrid2.DataSource = myListCollection;
this.DataGrid2.DataBind();
}
private ListItemCollection AddToCustomCollection()
{
ListItemCollection myListCollection = new ListItemCollection();
NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
"today");
NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
"imorgon");
NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
"veckan");
myListCollection.Add(myItem1);
myListCollection.Add(myItem2);
myListCollection.Add(myItem3);
return myListCollection;
}
//Inner Class which holds all properties needed to show news content and
listings
public class NewsItem
{
public NewsItem()
{
}
public NewsItem(string linkName, string linkUrl, string date)
{
}
public string linkName;
public string linkUrl;
public string date;
public string longDate;
}
}
//----
--
I'm using a collection class: (ListItemCollection.cs):
public class ListItemCollection:CollectionBase
{
public ListItemCollection()
{
//
// TODO: Add constructor logic here
//
}
public NewsContent.NewsItem Item(int index)
{
//the appropiate item is retrieved from the list object and
//explicitly cast to the ListItem type, then returned to the
//caller
return (NewsContent.NewsItem) List[index];
}
public int Add(NewsContent.NewsItem myNewsItem)
{
return List.Add(myNewsItem);
}
}Try setting the autogeneratecolumn property for this datagrid to True.
"viktor9990" wrote:

> I'm trying to bind a custom collection to an autogenerated datagrid withou
t
> success.
> I'm getting this error:
> DataGrid with id 'DataGrid2' could not automatically generate any columns
> from the selected data source.
> Could you help me to find a solution? What is the problem in my code? Than
ks.
> Here is my code (NewsContent.aspx):
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
> </form>
> //----
> Code behind:(NewsContent.aspx.cs).
> public class NewsContent{
> private void Page_Load(object sender, System.EventArgs e)
> {
> ListItemCollection myListCollection = AddToCustomCollection();
> this.DataGrid2.DataSource = myListCollection;
> this.DataGrid2.DataBind();
> }
> private ListItemCollection AddToCustomCollection()
> {
> ListItemCollection myListCollection = new ListItemCollection();
> NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
> "today");
> NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2"
,
> "imorgon");
> NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
> "veckan");
> myListCollection.Add(myItem1);
> myListCollection.Add(myItem2);
> myListCollection.Add(myItem3);
> return myListCollection;
> }
> //Inner Class which holds all properties needed to show news content and
> listings
> public class NewsItem
> {
> public NewsItem()
> {
> }
> public NewsItem(string linkName, string linkUrl, string date)
> {
> }
> public string linkName;
> public string linkUrl;
> public string date;
> public string longDate;
> }
> }
> //---
--
>
> I'm using a collection class: (ListItemCollection.cs):
> public class ListItemCollection:CollectionBase
> {
> public ListItemCollection()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public NewsContent.NewsItem Item(int index)
> {
> //the appropiate item is retrieved from the list object and
> //explicitly cast to the ListItem type, then returned to the
> //caller
> return (NewsContent.NewsItem) List[index];
> }
>
> public int Add(NewsContent.NewsItem myNewsItem)
> {
> return List.Add(myNewsItem);
> }
> }

trouble binding a datagrid to a custom collection

I'm trying to bind a custom collection to an autogenerated datagrid without
success.
I'm getting this error:

DataGrid with id 'DataGrid2' could not automatically generate any columns
from the selected data source.
Could you help me to find a solution? What is the problem in my code? Thanks.

Here is my code (NewsContent.aspx):
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
</form
//---------------------

Code behind:(NewsContent.aspx.cs).
public class NewsContent{

private void Page_Load(object sender, System.EventArgs e)
{

ListItemCollection myListCollection = AddToCustomCollection();
this.DataGrid2.DataSource = myListCollection;
this.DataGrid2.DataBind();
}

private ListItemCollection AddToCustomCollection()
{

ListItemCollection myListCollection = new ListItemCollection();
NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
"today");
NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
"imorgon");
NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
"veckan");
myListCollection.Add(myItem1);
myListCollection.Add(myItem2);
myListCollection.Add(myItem3);

return myListCollection;
}

//Inner Class which holds all properties needed to show news content and
listings
public class NewsItem
{
public NewsItem()
{
}
public NewsItem(string linkName, string linkUrl, string date)
{
}
public string linkName;
public string linkUrl;
public string date;
public string longDate;
}
}

//------------------------

I'm using a collection class: (ListItemCollection.cs):

public class ListItemCollection:CollectionBase
{
public ListItemCollection()
{
//
// TODO: Add constructor logic here
//
}

public NewsContent.NewsItem Item(int index)
{
//the appropiate item is retrieved from the list object and
//explicitly cast to the ListItem type, then returned to the
//caller
return (NewsContent.NewsItem) List[index];
}

public int Add(NewsContent.NewsItem myNewsItem)
{
return List.Add(myNewsItem);
}

}Try setting the autogeneratecolumn property for this datagrid to True.

"viktor9990" wrote:

> I'm trying to bind a custom collection to an autogenerated datagrid without
> success.
> I'm getting this error:
> DataGrid with id 'DataGrid2' could not automatically generate any columns
> from the selected data source.
> Could you help me to find a solution? What is the problem in my code? Thanks.
> Here is my code (NewsContent.aspx):
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
> </form>
> //---------------------
> Code behind:(NewsContent.aspx.cs).
> public class NewsContent{
> private void Page_Load(object sender, System.EventArgs e)
> {
> ListItemCollection myListCollection = AddToCustomCollection();
> this.DataGrid2.DataSource = myListCollection;
> this.DataGrid2.DataBind();
> }
> private ListItemCollection AddToCustomCollection()
> {
> ListItemCollection myListCollection = new ListItemCollection();
> NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
> "today");
> NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
> "imorgon");
> NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
> "veckan");
> myListCollection.Add(myItem1);
> myListCollection.Add(myItem2);
> myListCollection.Add(myItem3);
> return myListCollection;
> }
> //Inner Class which holds all properties needed to show news content and
> listings
> public class NewsItem
> {
> public NewsItem()
> {
> }
> public NewsItem(string linkName, string linkUrl, string date)
> {
> }
> public string linkName;
> public string linkUrl;
> public string date;
> public string longDate;
> }
> }
> //------------------------
>
> I'm using a collection class: (ListItemCollection.cs):
> public class ListItemCollection:CollectionBase
> {
> public ListItemCollection()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public NewsContent.NewsItem Item(int index)
> {
> //the appropiate item is retrieved from the list object and
> //explicitly cast to the ListItem type, then returned to the
> //caller
> return (NewsContent.NewsItem) List[index];
> }
>
> public int Add(NewsContent.NewsItem myNewsItem)
> {
> return List.Add(myNewsItem);
> }
> }

Monday, March 26, 2012

Trouble getting dropdownlist value

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.

<%@dotnet.itags.org. Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Trace="false" debug="true"%>
<%@dotnet.itags.org. import Namespace="System.Data.SqlClient" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.IO" %>

<script runat="server">

Sub Add_Info(s As Object, e as EventArgs)
lblMsg.Text = drpManufacturer.SelectedValue
End Sub

Sub Page_Load

Dim conPubs as SqlConnection
Dim cmdSQL as SqlCommand
Dim dtrAllProducts as SqlDataReader

'Retrieve records from database
conPubs = New SqlConnection("Server=xx.xx.xx.xx;uid=name;pwd=pwd;database=db")
cmdSQL = New SqlCommand("SELECT * FROM why3s_products", conPubs)
conPubs.Open()
dtrAllProducts = cmdSQL.ExecuteReader()

'Bind to Repeater
rptPrdList.DataSource = dtrAllProducts
rptPrdList.DataBind()

dtrAllProducts.Close()
conPubs.Close()

'Retrieve records from database
conPubs = New SqlConnection("Server=xx.xx.xx.xx;uid=name;pwd=pwd;database=db")
cmdSQL = New SqlCommand("SELECT manufacturers_name FROM why3s_manufacturers", conPubs)
conPubs.Open()
dtrAllProducts = cmdSQL.ExecuteReader()

'Bind to DropDownList
drpManufacturer.DataSource = dtrAllProducts
drpManufacturer.DataTextField = "manufacturers_name"
drpManufacturer.DataBind()

dtrAllProducts.Close()
conPubs.Close()
End Sub

</script>
<html>
<head>
<title>Add New Manufacturer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form id="frmAdd" name="frmAdd" action="addproduct.aspx" method="post" enctype="multipart/form-data" runat="server">
<!--#include file="inc_top_menu.aspx" --><br>

<table cellspacing="0" cellpadding="0" width="750" border="0">
<tbody>
<tr>

<td width="125" valign="top"> <asp:validationsummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" HeaderText="Missing:" DisplayMode="List"></asp:validationsummary>
</td>
<td width="625">
<table cellspacing="2" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td>Manufacturer:</td>
<td><asp:dropdownlist ID="drpManufacturer" runat="server"></asp:dropdownlist>
- <em><font size="2" face="Verdana, Arial, Helvetica, sans-serif">If
not in list please create before you continue.</font></em></td>
</tr>
<tr>
<td width="26%"> Product Model Name:</td>
<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>
</tr>
<tr>
<td>Product Fullmodel Name:</td>
<td><asp:textbox AutoPostBack="false" ID="txtFullModel" MaxLength="60" runat="server" /> <asp:requiredfieldvalidator ControlToValidate="txtFullModel" ErrorMessage="Fullmodel Name" Text="Required" runat="server" /> </td>
</tr>
<tr>
<td> Product Image:</td>
<td><input name="inpFileUpload" type="file" id="inpFileUpload" size="40" maxlength="60" Runat="Server">
<font size="1" face="Verdana, Arial, Helvetica, sans-serif"><em>300kb
max file size.</em></font></td>
</tr>
<tr>
<td> Product Description</td>
<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>
</tr>
<tr>
<td>Product Price:</td>
<td><asp:textbox ID="txtPrice" MaxLength="10" runat="server" /> <asp:requiredfieldvalidator ControlToValidate="txtPrice" ErrorMessage="Price" InitialValue="Required" runat="server" Text="Required" /> </td>
</tr>
<tr>
<td>Product Retail Price:</td>
<td><asp:textbox ID="txtRetail" MaxLength="10" runat="server" /></td>
</tr>
<tr>
<td>Product Cost:</td>
<td><asp:textbox ID="txtCost" MaxLength="10" runat="server" /></td>
</tr>
<tr>
<td>Product Wholesale Price:</td>
<td><asp:textbox ID="txtWholesale" MaxLength="10" runat="server" /></td>
</tr>
<tr>
<td>Product Weight:</td>
<td><asp:textbox ID="txtWeight" MaxLength="7" runat="server" /></td>
</tr>
<tr>
<td>Product Status:</td>
<td><div align="left">
<asp:dropdownlist ID="drpStatus" runat="server">
<asp:listitem Text="Show" runat="server"></asp:listitem>
<asp:listitem Text="Hide" runat="server"></asp:listitem>
</asp:dropdownlist>
<em><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Display
vacuum on page.</font></em></div></td>
</tr>
<tr>
<td>Product Sold-To-Dt:</td>
<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>
</tr>
<tr>
<td>Product Show Button:</td>
<td><asp:dropdownlist ID="drpShowBuy" runat="server">
<asp:listitem Text="Show" runat="server"></asp:listitem>
<asp:listitem Text="Hide" runat="server"></asp:listitem>
</asp:dropdownlist> <em><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Do
not display the buy button.</font></em></td>
</tr>
<tr>
<td>Product Special Notify:</td>
<td><asp:textbox ID="txtSpecialNotify" MaxLength="55" runat="server" /></td>
</tr>
<tr>
<td>Product Quantity:</td>
<td><asp:textbox ID="txtQuantity" MaxLength="4" runat="server" Text="0" /></td>
</tr>
<tr>
<td> </td>
<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>
</tr>
<tr>
<td> </td>
<td><asp:label ID="lblMsg" runat="server"></asp:label></td>
</tr>

</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
<br />
<center>
<asp:repeater EnableViewState="false" ID="rptPrdList" runat="server">
<headertemplate>
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Image</th>
<th>Entry_Dt</th>
<th>Description</th>
</tr>
</headertemplate>

<itemtemplate>
<tr bgcolor="#CCFFFF">

<td><a href="http://links.10026.com/?link=updatemanufacturer.aspx?ID=<%# Container.DataItem("manufacturers_id") %>"><%# Container.DataItem("manufacturers_id") %></a></td>
<td><%# Container.DataItem("manufacturers_name") %></td>
<td><%# Container.DataItem("manufacturers_image") %></td>
<td><%# Container.DataItem("manufacturers_entry_dt") %></td>
<td><%# Container.DataItem("manufacturers_description") %></td>
</tr>
</itemtemplate>

<AlternatingItemTemplate>
<tr bgcolor="#99FF66">
<td><%# Container.DataItem("manufacturers_id") %></td>
<td><%# Container.DataItem("manufacturers_name") %></td>
<td><%# Container.DataItem("manufacturers_image") %></td>
<td><%# Container.DataItem("manufacturers_entry_dt") %></td>
<td><%# Container.DataItem("manufacturers_description") %></td>
</tr>
</AlternatingItemTemplate>

<footertemplate>
</table>
</footertemplate>
</asp:repeater>
</center>
</body>
</html>1)
Set the DataTextField for the text to display.
Set the DataValueField for the value for that text.

2) You need to check of the PostBack

If Not Page.IsPostBack
'Do this code if the page isn't posted back
End If

3) Why are you creating 2 connections in the Page_Load event?
Try something like this

Sub Page_Load

Dim conPubs as SqlConnection
Dim cmdProducts as SqlCommand
Dim cmdManufacturers as SqlCommand
Dim dtrAllProducts as SqlDataReader
Dim dtrAllManufacturers As SqlDataReader

'Retrieve records from database
conPubs = New SqlConnection("Server=xx.xx.xx.xx;uid=name;pwd=pwd;database=db")

cmdProducts = New SqlCommand("SELECT * FROM why3s_products", conPubs)
cmdManufacturers = New SqlCommand("SELECT manufacturers_name FROM why3s_manufacturers", conPubs)

Try
conPubs.Open()
dtrAllProducts = cmdProducts.ExecuteReader()
dtrAllManufacturers = cmdManufacturers.ExecuteReader()

'Bind to Products to Repeater
rptPrdList.DataSource = dtrAllProducts
rptPrdList.DataBind()

'Bind to DropDownList
drpManufacturer.DataSource = dtrAllManufacturers
drpManufacturer.DataTextField = "manufacturers_name"
drpManufacturer.DataValueField = "manufacturers_ID"
drpManufacturer.DataBind()

dtrAllProducts.Close()
dtrManufacturers.Close()

conPubs.Close()

Catch ex As Exception
Response.write("Error Occurred: " & ex.Message & "<br>" & ex.StackTrace)
End Try

End Sub
Thanks for the quick response.

I changed to 1 connection but get the following at the top of my page:

Error Occurred: There is already an open DataReader associated with this Connection which must be closed first. .....

This points to the following line:
dtrAllManufacturers = cmdManufacturers.ExecuteReader()

Setting the DataValueField does make sense now.

I am very new to asp.net. Is the Try, Catch ex As Exception the new On Error?

Thanks again for your help.
okay, open the first reader, process the data, close the reader, then do the same with the second reader.
Yes, this does work.

My other issue is I can't get the value selected to return.

Is it due to the IsPostBack? I have this in a On_Click event so does the Page_Load reset my selection?

<%@. Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Trace="false" debug="true"%>
<%@. import Namespace="System.Data.SqlClient" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.IO" %>

<script runat="server">

Sub Add_Info(s As Object, e as EventArgs)
If IsValid Then
'Query db to see if product is found if not then insert new record.
Dim conPubs as SqlConnection
Dim sSQL as SqlCommand
Dim sTmpSQL as String
Dim sInsertSQL as String
Dim cmdInsertSQL as SqlCommand
Dim dtrUsers as SqlDataReader
Dim iFoundPrds as Integer
Dim iInsertCnt as Integer
Dim sFileName as String
Dim sFullImagePath as String
Dim sFolder as String
Dim sImageSize as String

'Get the name of the file posted
sFileName = inpFileUpload.PostedFile.Filename
'In bytes 29.9 KB (30,704 bytes)
'Don't want to allow more then 307,200 bytes
sImageSize = inpFileUpload.PostedFile.ContentLength
sFileName = Path.GetFileName(sFileName) sFolder = "C:\websites\dir1\dir2\site.com\images\"

'Determine if an image is sent.
If Len(sFileName) > 0 Then
If sImageSize <= 307200 Then
sFullImagePath = "images\" & sFileName
End if
End if

'Create the directory if it does not exist
If (not Directory.Exists(sFolder)) Then
Directory.CreateDirectory(sFolder)
End if

iInsertCnt = 0
conPubs = New SqlConnection("Server=xx.xx.xx.xx;uid=name;pwd=pwd;database=dbname")
conPubs.Open()
sTmpSQL = "SELECT count(*) as ProductsFound FROM why3s_products where UPPER(RTRIM(products_model)) = '" & UCase(txtModel.Text) & "' AND manufacturers_id = 1"
lblMsg.Text = sTmpSQL
sSQL = New SqlCommand(sTmpSQL, conPubs)
dtrUsers = sSQL.ExecuteReader()
While dtrUsers.Read()
iFoundPrds = dtrUsers("ProductsFound")
End While
dtrUsers.Close()
If iFoundPrds = 0 Then
'lblError.Text = "No users found"
sInsertSQL = "INSERT INTO why3s_products (products_quantity, products_model, products_fullmodel, products_image, products_price, products_retail_price, products_cost, products_wholesale_price, products_entry_dt, products_last_change_dt, products_weight, products_status, products_sold_to_dt, products_description, products_show_buy, products_special_notify, manufacturers_id) values (" & txtQuantity.Text & ", '" & txtModel.Text & "', '" & txtFullModel.Text & "', '" & sFullImagePath & "', " & txtPrice.Text & ", " & txtRetail.Text & ", " & txtCost.Text & ", " & txtWholesale.Text & ", getdate(), getdate(), " & txtWeight.Text & ", 0, " & txtSTD.Text & ", '" & txtDescription.Text & "', 1, '" & txtSpecialNotify.Text & "', 1)"
cmdInsertSQL = New SqlCommand(sInsertSQL, conPubs)
iInsertCnt = cmdInsertSQL.ExecuteNonQuery()
'lblMsg.Text = "You have inserted " & iInsertCnt & " records."

If Len(sFileName) > 0 Then
'Check to see if file already exists
If File.Exists(sFolder & sFileName)
'Only save if file is less then 300kb
If sImageSize <= 307200 Then
'Save file to server
inpFileUpload.PostedFile.SaveAs(sFolder & sFileName)
End if
End if
End if
Else
'lblError.Text = iFoundUsers & " users found."
'lblMsg.Text = "User already found. Please try again."
End iF
conPubs.Close()
'If iInsertCnt > 0 Then
'Response.Redirect("addproduct.aspx")
'End if
Else
'lblError.Text = "Not IsValid"
lblMsg.Text = vbNullString
End if
End Sub

Sub Page_Load

Dim conPubs as SqlConnection
Dim cmdProducts as SqlCommand
Dim cmdManufacturers as SqlCommand
Dim dtrAllProducts as SqlDataReader
Dim dtrAllManufacturers as SqlDataReader

'Retrieve records from database
conPubs = New SqlConnection("Server=xx.xx.xx.xx;uid=name;pwd=pwd;database=dbname")
cmdProducts = New SqlCommand("SELECT * FROM why3s_products", conPubs)
cmdManufacturers = New SqlCommand("SELECT manufacturers_name, manufacturers_id FROM why3s_manufacturers", conPubs)

'Try
conPubs.Open()

dtrAllProducts = cmdProducts.ExecuteReader()

'Bind Manufacturer to Repeater
rptPrdList.DataSource = dtrAllProducts
rptPrdList.DataBind()
dtrAllProducts.Close()

dtrAllManufacturers = cmdManufacturers.ExecuteReader()

'Bind to DropDownList
drpManufacturer.DataSource = dtrAllManufacturers
drpManufacturer.DataTextField = "manufacturers_name"
drpManufacturer.DataValueField = "manufacturers_id"
drpManufacturer.DataBind()

dtrAllManufacturers.Close()

conPubs.Close()

'Catch ex As Exception
'Response.Write("Error Occurred: " & ex.Message & "<br>" & ex.StackTrace)
'End Try
End Sub

</script>
<html>
<head>
<title>Add New Manufacturer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form id="frmAdd" name="frmAdd" action="addproduct.aspx" method="post" enctype="multipart/form-data" runat="server">
<!--#include file="inc_top_menu.aspx" --><br>

<table cellspacing="0" cellpadding="0" width="750" border="0">
<tbody>
<tr>

<td width="125" valign="top"> <asp:validationsummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" HeaderText="Missing:" DisplayMode="List"></asp:validationsummary>
</td>
<td width="625">
<table cellspacing="2" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td>Manufacturer:</td>
<td><asp:dropdownlist ID="drpManufacturer" runat="server"></asp:dropdownlist>
- <em><font size="2" face="Verdana, Arial, Helvetica, sans-serif">If
not in list please create before you continue.</font></em></td>
</tr>
<tr>
<td width="26%"> Product Model Name:</td>
<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>
</tr>
<tr>
<td>Product Fullmodel Name:</td>
<td><asp:textbox AutoPostBack="false" ID="txtFullModel" MaxLength="60" runat="server" /> <asp:requiredfieldvalidator ControlToValidate="txtFullModel" ErrorMessage="Fullmodel Name" Text="Required" runat="server" /> </td>
</tr>
<tr>
<td> Product Image:</td>
<td><input name="inpFileUpload" type="file" id="inpFileUpload" size="40" maxlength="60" Runat="Server">
<font size="1" face="Verdana, Arial, Helvetica, sans-serif"><em>300kb
max file size.</em></font></td>
</tr>
'..... REMOVE CODE TO SHORTEN

<tr>
<td> </td>
<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>
</tr>
<tr>
<td> </td>
<td><asp:label ID="lblMsg" runat="server"></asp:label></td>
</tr>

</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
<br />
<center>
<asp:repeater EnableViewState="false" ID="rptPrdList" runat="server">
<headertemplate>
<table border="1">
<tr>
<th>ID</th>
<th>Model</th>
<th>Manufacturers ID</th>
</tr>
</headertemplate>

<itemtemplate>
<tr bgcolor="#CCFFFF">
<td><a href="http://links.10026.com/?link=updateproduct.aspx?ID=<%# Container.DataItem("products_id") %>"><%# Container.DataItem("products_id") %></a></td>
'REMOVED CODE TO FIT
<td><%# Container.DataItem("manufacturers_id") %></td>
</tr>
</itemtemplate>

<AlternatingItemTemplate>
<tr bgcolor="#99FF66">
<td><a href="http://links.10026.com/?link=updateproduct.aspx?ID=<%# Container.DataItem("products_id") %>"><%# Container.DataItem("products_id") %></a></td>
'REMOVED CODE TO FIT
<td><%# Container.DataItem("products_model") %></td>
<td><%# Container.DataItem("manufacturers_id") %></td> </tr>
</AlternatingItemTemplate>

<footertemplate>
</table>
</footertemplate>
</asp:repeater>
</center>
</body>
</html>
Where are you trying to retrieve it at?

Dim ManufacturerID As Integer

ManufacturerID = drpManufacturer.SelectedValue
Well, I did find out that it only works if I do a 'Not IsPostBack' on my On_Load. It must be reloading the form then doing the Button On_CLick.

Is it possible to run my on_click code then refresh the page?

This doesn't really relate to this subject but you seem to have an extremely good handle on .net. When working with forms do you have a function after a users clicks and submits your data that resets the form to the original state or is there code that does this for you?

Thanks again for all your help.
You could set the "EnableViewState" property to "False" on all the controls that have that property.