DataList and [bound] ListBox

B

Beorn

Does anybody have experience using a bound ListBox within a DataList?

The DataList should repeat for a list of Categories, each category
holds a list of components under that category. The User wil select a
component for each category (with an associated price....) and click
update, the adjusted price (sum of all selelcted components) is show
in the footer. Should be simple.

The code is chopped and changed a little for simplicity...but should
give the idea.

Thanks

Beorn

*************************************************
CODE
*************************************************
<Script Language="VB" RunAt="Server">

....

Sub Page_Load(Src As Object, e As EventArgs)
' Populate ComponentList with the Categories
ComponentList.DataSource = ExecuteSelect("Select *
from ComponentCategories Order By SortOrder")
ComponentList.DataBind()

End Sub

Sub Item_Created(sender As Object, e As DataListItemEventArgs)

If e.Item.ItemType = ListItemType.Item _
Or e.Item.ItemType = ListItemType.AlternatingItem _
Or e.Item.ItemType = ListItemType.SelectedItem _
Or e.Item.ItemType = ListItemType.EditItem Then

ds = ExecuteSelect("Select * from Components where Category="
& e.Item.DataItem.Row("Category"))
For Each dr in ds.Tables(0).Rows
li = new ListItem(dr("Description"),
dr("ComponentID"))
If dr("ComponentID") = ??? Then
li.Selected = True
Price += dr("SystemPrice")
End If
compLst.Items.Add(li)
Next
End If

End Sub

....

</Script>

<Form EnableViewState="True" RunAt="server">

<asp:DataList id="ComponentList"
CellPadding="5"
CellSpacing="1"
ExtractTemplateRows="False"
GridLines="None"
RepeatDirection="Vertical"
RepeatLayout="Table"
ShowFooter="True"
ShowHeader="False"
OnItemCreated="Item_Created"
runat="server">

<ItemTemplate>
<tr>
<td><b><asp:Label Id="Category"
RunAt="Server" /></b></td>
<td><asp:ListBox Id="compLst"
RunAt="server" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<h2>Total Price <asp:Label Id="Price"
RunAt="Server" /></h2>
</FooterTemplate>
</asp:DataList>

<asp:ImageButton ID="Update" RunAt="Server"
ImageAlign="left"
ImageUrl="images/updateup.gif"
/>
</Form>
 
A

Alvin Bruney [MVP]

Your post went unanswered. Have you resolved this issue? If you still need
help, please post the original question with your request.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top