[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Richard Price

1/23/2003 5:40:00 PM

If I cannot fix the code below and I recreate the control
as a server HTMLSELECT box then how do I add the options
to it in the codebehind file?


How do you add a value to a datadropdownlist that has to
be bound as it is within a datarepeater and itemdata?

I can't get this to work and I have tried for a long time
now. Can anyone help me out?

I have a class called ProductData that builds a table of
data from a call to a web service.

I use the datatable in a datarepeater to create table
rows. I get the code, displayed in the table perfectly.

However, when I try add a datadropdownlist to display the
colour I get no where.

The data for the colour is returned from the web service
as an array of values ("purple,blue,white")

I cannot figure out how to add it to the data in the
class and therefore to the datadropdownlist.

If I try to access the dropdownlist directly and add
items to it I get an object instance not found error.

Here is the code to add the data to the table
*********************************************

Dim objProductsData As New ProductsData()

objProducts = CType(context.Handler, EnterProducts)
objProductsData.CreateDataSource()
strCode1 = objProducts.propItem1.Trim

strColour = websrvCalculations.colour(strCode1)

Dim arrColour() As String
arrColour = strColour.Split(",")

'WHAT CAN I DO HERE?

strWeight = websrvCalculations.WeightofProduct(strCode1)
objProductsData.AddProductsDataRow(strCode1, _
strColour)


Here is the code to bind the table to the datarepeater
control
**********************************************************
****

dv = New DataView(objProductsData.ProductsDataTable)
RepProducts.DataSource = dv
RepProducts.DataBind()
objProductsData = Nothing



Here is the ProductsData class
******************************
Public Class ProductsData

Private m_Code As String
Private m_Colour As String
Private m_ProductsTable As New DataTable()
Private m_ProductsRow As DataRow
Private m_ProductsDataView As ICollection

Public Sub AddProductsDataRow(ByVal strCode As String,
ByVal strName As String, ByVal strColour As String, ByVal
strSize As String, ByVal strWeight As String, ByVal
strAvailability As String)

m_ProductsRow = m_ProductsTable.NewRow
m_ProductsRow(0) = strCode
m_ProductsRow(1) = strColour
m_ProductsTable.Rows.Add(m_ProductsRow)
End Sub
Public Sub CreateDataSource()
m_ProductsTable.Columns.Add(New DataColumn("Code",
GetType(String)))
m_ProductsTable.Columns.Add(New DataColumn
("Colour",
GetType(String)))
End Sub

Property ProductsDataView() As ICollection

Set(ByVal Value As ICollection)
m_ProductsDataView = Value
End Set

Get
Return m_ProductsDataView
End Get
End Property
ReadOnly Property ProductsDataTable()
Get
Return m_ProductsTable
End Get
End Property
End Class

Here is the datarepeater HTML code that refuses to work
*******************************************************

<asp:repeater id=RepProducts runat="server">
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "Code") %>
</td>
<td>
<asp:DropDownList id=CmbColour runat="server"
DataSource='<% dv %>'
DataTextField='<% DataBinder.Eval
(Container.DataItem, "Colour") %>'
></asp:DropDownList>
</td>
</tr>
</ItemTemplate>
</asp:repeater>