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">
<aspataList 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>
</aspataList>
<asp:ImageButton ID="Update" RunAt="Server"
ImageAlign="left"
ImageUrl="images/updateup.gif"
/>
</Form>
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">
<aspataList 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>
</aspataList>
<asp:ImageButton ID="Update" RunAt="Server"
ImageAlign="left"
ImageUrl="images/updateup.gif"
/>
</Form>