Right this is really begining to do my head in now. Help would be really appreciated 
There is a screenshot at this URL of the control i'm trying to get working:
What I'm trying to achieve is a page that retrieves all the values from a ProductDefinition table into a datatable where its filtered for only those selected in the ProductCategory DropDownList and bound to the ProductDefinition ListBox (right).
When a user changes the selection in the category DropDownList the values in the ProductDefinition ListBox update.
When a user selects a product from this ListBox and clicks the Add button the selection is added to the CompanyProducts ListBox (left). Conversely if they click the Remove button the Selected Value in the ComapnyProducts ListBox is removed.
The way I was trying to achieve this was by Creating a new DataTable on PageLoad and Bind it to the CompanyProducts ListBox. When Add is clicked a new row is created in this DataTable and populated with the values selected in the ProductDefinition ListBox. Values would be removed from the CompanyProducts ListBox by removing the row from the DataTable.
I've tried so many methods and just can't get it working!
I think the biggest problems i'm getting are:
- Referencing the new datatable (created by the NewDataTable Function) from the AddBtn_Click Subroutine
- Getting the right hand ListBox to update properly
- Getting the AddBtn to work at all
Perhaps my whole approach is wrong - any advice is gladly accepted cos i've got a deadline on Tuesday.
Anyway heres my (bug ridden) code:
==========================================================
<%@ Page language="VB" Debug="true"%>
<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.Data" %>
<%@ Register TagPrefix="portal" TagName="Banner" Src="~/DesktopPortalBanner.ascx" %>
<script runat="server">
Function ProdDefList() As ICollection
Dim products As New ASPNetPortal.ProductsDB()
Dim myDataSet = products.GetAllProductDefinitions()
Dim myDataView As New DataView(myDataSet.Tables("tblProductDefinitions"
)
Dim strCategoryID = CategoryList.SelectedItem.Value
' Filter the DataView for only rows of the selected Category
myDataView.RowFilter = "CategoryID = " & strCategoryID
Return myDataView
End Function
Function NewDataTable() As ICollection
' Create a new DataTable in the existing DataSet for the Companies
' Selected Products
Dim ds As New DataSet
Dim dt As New DataTable
dt = ds.Tables("CompanyProducts"
dt.Columns.Add(New DataColumn("ProductDefinitionID", GetType(Int32)))
dt.Columns.Add(New DataColumn("Description", GetType(String)))
Dim myDataView = dt.DefaultView
'Return myDataView
End Function
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
If Not IsPostBack Then
Email.Text = Request.QueryString("email"
' Specify the DataView as the Data Source of the ProductList ListBox
' and Bind it
ProductDefinitionList.DataSource = ProdDefList()
ProductDefinitionList.DataValueField = "ProductDefinitionID"
ProductDefinitionList.DataTextField = "Description"
ProductDefinitionList.DataBind()
'Bind the CompanyProducts ListBox to the new DataTable
CompanyProducts.DataSource = NewDataTable()
CompanyProducts.DataValueField = "ProductDefinitionID"
CompanyProducts.DataTextField = "Description"
CompanyProducts.DataBind()
End If
End Sub
Sub AddBtn_Click(ByVal sender As Object, ByVal E As EventArgs)
Dim dt As New DataTable
' ??
' ??
' ??
Dim dr As DataRow
dr = dt.NewRow()
dr("ProductDefinitionID"
= ProductDefinitionList.SelectedItem.Value
dr("Description"
= ProductDefinitionList.SelectedItem.Text
dt.Rows.Add(dr)
End Sub
Sub RemoveBtn_Click(ByVal sender As Object, ByVal E As EventArgs)
' ??
' ??
' ??
End Sub
Sub RegisterBtn_Click(ByVal sender As Object, ByVal E As EventArgs)
' Set the user's authentication name to the userId
FormsAuthentication.SetAuthCookie(Email.Text, False)
' Redirect browser back to home page'
Response.Redirect("~/DesktopDefault.aspx"
End Sub
</script>
<script language="JavaScript">
<!--
function openWindow(filename) {
window.open (filename, "newwindow", "height=495, width=625, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no"
}
//-->
</script>
<html>
<head>
<link rel="stylesheet" href='<%= Request.ApplicationPath & "/Portal.css" %>' type="text/css" />
</head>
<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<form method="post" id="frmSubscribe" runat="server">
<table width="100%" cellspacing="0" cellpadding="0">
<tr valign="top">
<td colspan="2">
<portal:Banner ShowTabs="false" runat="server" id="Banner1" />
</td>
</tr>
<tr>
<td>
<br>
<table width="98%" cellspacing="0" cellpadding="4" border="0">
<tr>
<td width="90">
</td>
<td width="*">
<table cellpadding="2" cellspacing="1" border="0" width="600">
<tr>
<td>
<span class="Head">Company/Organistion Information </span>
</td>
</tr>
<tr>
<td>
<hr noshade size="1">
</td>
</tr>
<tr>
<td>
<asp:TextBox Visible="False" id="Email" runat="server" />
</td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="50%">
<span class="ItemTitle">Product Details</span>
<br>
<br>
</td>
<td align="right" valign="top" ><a href="javascript
penWindow('InfoProductDetails.aspx')"><img src="../images/info.gif" width="35" height="16" border="0"></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td class="normal">Category</td>
<td> </td>
<td class="normal">Product Categories</td>
</tr>
<tr>
<td>
<asp:TextBox id="ProductCategory" runat="server" /><br>
</td>
<td> </td>
<td>
<asp
ropDownList id="CategoryList" AutoPostBack="True" runat="server" CssClass="Normal">
<asp:ListItem Value="1">Exterior</asp:ListItem>
<asp:ListItem Value="2">Chassis/Underbody</asp:ListItem>
<asp:ListItem Value="3">Powertrain</asp:ListItem>
<asp:ListItem Value="4">Interior</asp:ListItem>
<asp:ListItem Value="5">Electrical/Electronic</asp:ListItem>
<asp:ListItem Value="6">Other</asp:ListItem>
</asp
ropDownList>
</td>
</tr>
<tr>
<td class="normal">Company Products</td>
<td> </td>
<td class="normal">Products</td>
</tr>
<tr>
<td>
<asp:ListBox id="CompanyProducts" width="250" Rows="10" runat="server" CssClass="Normal" />
</td>
<td width="45" align="center">
<asp:Button id="btnAdd" runat="server" Text=" << " Onclick="AddBtn_Click" CssClass="Normal" />
<br><br>
<asp:Button id="btnRemove" runat="server" Text=" >> " Onclick="RemoveBtn_Click" CssClass="Normal" />
</td>
<td>
<asp:ListBox id="ProductDefinitionList" width="250" Rows="10" runat="server" Cssclass="Normal" />
</td>
</tr>
</table>
<br>
<hr noshade size="1">
</td>
</tr>
<tr valign="top">
<td>
<p>
<asp:LinkButton CssClass="CommandButton" OnClick="RegisterBtn_Click" Text="Finish" runat="server" ID="Linkbutton1" NAME="Linkbutton1" />
<br>
<br>
<p>
<asp:Label id="Message" CssClass="NormalRed" runat="server" /></p>
</td>
</tr>
</table>
<P> </P>
<P> </P>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</HTML>
===========================================================
cheers,
si
There is a screenshot at this URL of the control i'm trying to get working:
What I'm trying to achieve is a page that retrieves all the values from a ProductDefinition table into a datatable where its filtered for only those selected in the ProductCategory DropDownList and bound to the ProductDefinition ListBox (right).
When a user changes the selection in the category DropDownList the values in the ProductDefinition ListBox update.
When a user selects a product from this ListBox and clicks the Add button the selection is added to the CompanyProducts ListBox (left). Conversely if they click the Remove button the Selected Value in the ComapnyProducts ListBox is removed.
The way I was trying to achieve this was by Creating a new DataTable on PageLoad and Bind it to the CompanyProducts ListBox. When Add is clicked a new row is created in this DataTable and populated with the values selected in the ProductDefinition ListBox. Values would be removed from the CompanyProducts ListBox by removing the row from the DataTable.
I've tried so many methods and just can't get it working!
I think the biggest problems i'm getting are:
- Referencing the new datatable (created by the NewDataTable Function) from the AddBtn_Click Subroutine
- Getting the right hand ListBox to update properly
- Getting the AddBtn to work at all
Perhaps my whole approach is wrong - any advice is gladly accepted cos i've got a deadline on Tuesday.
Anyway heres my (bug ridden) code:
==========================================================
<%@ Page language="VB" Debug="true"%>
<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.Data" %>
<%@ Register TagPrefix="portal" TagName="Banner" Src="~/DesktopPortalBanner.ascx" %>
<script runat="server">
Function ProdDefList() As ICollection
Dim products As New ASPNetPortal.ProductsDB()
Dim myDataSet = products.GetAllProductDefinitions()
Dim myDataView As New DataView(myDataSet.Tables("tblProductDefinitions"
Dim strCategoryID = CategoryList.SelectedItem.Value
' Filter the DataView for only rows of the selected Category
myDataView.RowFilter = "CategoryID = " & strCategoryID
Return myDataView
End Function
Function NewDataTable() As ICollection
' Create a new DataTable in the existing DataSet for the Companies
' Selected Products
Dim ds As New DataSet
Dim dt As New DataTable
dt = ds.Tables("CompanyProducts"
dt.Columns.Add(New DataColumn("ProductDefinitionID", GetType(Int32)))
dt.Columns.Add(New DataColumn("Description", GetType(String)))
Dim myDataView = dt.DefaultView
'Return myDataView
End Function
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
If Not IsPostBack Then
Email.Text = Request.QueryString("email"
' Specify the DataView as the Data Source of the ProductList ListBox
' and Bind it
ProductDefinitionList.DataSource = ProdDefList()
ProductDefinitionList.DataValueField = "ProductDefinitionID"
ProductDefinitionList.DataTextField = "Description"
ProductDefinitionList.DataBind()
'Bind the CompanyProducts ListBox to the new DataTable
CompanyProducts.DataSource = NewDataTable()
CompanyProducts.DataValueField = "ProductDefinitionID"
CompanyProducts.DataTextField = "Description"
CompanyProducts.DataBind()
End If
End Sub
Sub AddBtn_Click(ByVal sender As Object, ByVal E As EventArgs)
Dim dt As New DataTable
' ??
' ??
' ??
Dim dr As DataRow
dr = dt.NewRow()
dr("ProductDefinitionID"
dr("Description"
dt.Rows.Add(dr)
End Sub
Sub RemoveBtn_Click(ByVal sender As Object, ByVal E As EventArgs)
' ??
' ??
' ??
End Sub
Sub RegisterBtn_Click(ByVal sender As Object, ByVal E As EventArgs)
' Set the user's authentication name to the userId
FormsAuthentication.SetAuthCookie(Email.Text, False)
' Redirect browser back to home page'
Response.Redirect("~/DesktopDefault.aspx"
End Sub
</script>
<script language="JavaScript">
<!--
function openWindow(filename) {
window.open (filename, "newwindow", "height=495, width=625, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no"
}
//-->
</script>
<html>
<head>
<link rel="stylesheet" href='<%= Request.ApplicationPath & "/Portal.css" %>' type="text/css" />
</head>
<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<form method="post" id="frmSubscribe" runat="server">
<table width="100%" cellspacing="0" cellpadding="0">
<tr valign="top">
<td colspan="2">
<portal:Banner ShowTabs="false" runat="server" id="Banner1" />
</td>
</tr>
<tr>
<td>
<br>
<table width="98%" cellspacing="0" cellpadding="4" border="0">
<tr>
<td width="90">
</td>
<td width="*">
<table cellpadding="2" cellspacing="1" border="0" width="600">
<tr>
<td>
<span class="Head">Company/Organistion Information </span>
</td>
</tr>
<tr>
<td>
<hr noshade size="1">
</td>
</tr>
<tr>
<td>
<asp:TextBox Visible="False" id="Email" runat="server" />
</td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="50%">
<span class="ItemTitle">Product Details</span>
<br>
<br>
</td>
<td align="right" valign="top" ><a href="javascript
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td class="normal">Category</td>
<td> </td>
<td class="normal">Product Categories</td>
</tr>
<tr>
<td>
<asp:TextBox id="ProductCategory" runat="server" /><br>
</td>
<td> </td>
<td>
<asp
<asp:ListItem Value="1">Exterior</asp:ListItem>
<asp:ListItem Value="2">Chassis/Underbody</asp:ListItem>
<asp:ListItem Value="3">Powertrain</asp:ListItem>
<asp:ListItem Value="4">Interior</asp:ListItem>
<asp:ListItem Value="5">Electrical/Electronic</asp:ListItem>
<asp:ListItem Value="6">Other</asp:ListItem>
</asp
</td>
</tr>
<tr>
<td class="normal">Company Products</td>
<td> </td>
<td class="normal">Products</td>
</tr>
<tr>
<td>
<asp:ListBox id="CompanyProducts" width="250" Rows="10" runat="server" CssClass="Normal" />
</td>
<td width="45" align="center">
<asp:Button id="btnAdd" runat="server" Text=" << " Onclick="AddBtn_Click" CssClass="Normal" />
<br><br>
<asp:Button id="btnRemove" runat="server" Text=" >> " Onclick="RemoveBtn_Click" CssClass="Normal" />
</td>
<td>
<asp:ListBox id="ProductDefinitionList" width="250" Rows="10" runat="server" Cssclass="Normal" />
</td>
</tr>
</table>
<br>
<hr noshade size="1">
</td>
</tr>
<tr valign="top">
<td>
<p>
<asp:LinkButton CssClass="CommandButton" OnClick="RegisterBtn_Click" Text="Finish" runat="server" ID="Linkbutton1" NAME="Linkbutton1" />
<br>
<br>
<p>
<asp:Label id="Message" CssClass="NormalRed" runat="server" /></p>
</td>
</tr>
</table>
<P> </P>
<P> </P>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</HTML>
===========================================================
cheers,
si