469,282 Members | 1,955 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

DataList and [bound] ListBox

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>

Nov 18 '05 #1
0 1150

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike Malter | last post: by
reply views Thread by VbScripter | last post: by
3 posts views Thread by Danny Tuppeny | last post: by
1 post views Thread by Theo | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.