I have a page that lists a lot of items in a repeater. It has a Checkbox and a Description. The user will check the items they want to pay for and click the Next button. Then I want to display the same info. except only the items that were selected and hide the Checkbox column and display a Price column along with a total. I also would like the user to be able to go Back if they want to change their selections.
My original idea was to have a panel with the first repeater in it at the first step and then at the second step hide the first panel and display the second panel having a different repeater with only the selected items and the Price. When I go back and show the first panel and hide the second panel the first repeater loses the original selections (viewstate is on).
I think there must be a better way to do this. What is the best way to do this? Thanks.
do something like
Page_Load()
If Not Page.IsPostBack then
bind.repeater.here
else
'no bind
end if
HTH
Yes, that was what I was doing wrong. Thanks.
Do you know how I can pass the checked selections between step 1 and 2? At step 2 I hide the checkbox column like this:
datagrid.Columns(0).Visible =False
Then I have a Back button to do this to show the checked items again:
datagrid.Columns(0).Visible = True
But then I lose the items that were checked previously.
Well, I still can't see your code - of course there are a lot of different ways to accomplish this - here's one
<%@. Page Language="vb" %>
<%@. import Namespace="System.Data" %>
<script runat="server">
Function CreateDataSource() As ICollection
Dim dt As DataTable
Dim dr As DataRow
Dim i As Integer
'create a DataTable
dt = New DataTable
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("DateTimeValue", GetType(DateTime)))
dt.Columns.Add(New DataColumn("Price", GetType(decimal)))
'Make some rows and put some sample data in
For i = 1 To 15
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " & i.ToString()
dr(2) = DateTime.Now.ToShortTimeString
dr(3) = i*2.75
dt.Rows.Add(dr)
Next
'return a DataView to the DataTable
CreateDataSource = New DataView(dt)
End Function
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
BindList
End If
End Sub
Sub BindList
DataList1.DataSource= CreateDataSource()
DataList1.DataBind
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
Panel1.visible=false
Panel2.visible=true
Dim checked_dt As DataTable
Dim checked_dr As DataRow
Dim isitchecked As CheckBox
dim pricelabel as label
dim descriptionlabel as label
Dim itemlabel as label
dim runningtotal as decimal =0.0
checked_dt= New DataTable
checked_dt.Columns.Add(New DataColumn("PartNumber", GetType(Integer)))
checked_dt.Columns.Add(New DataColumn("Description", GetType(string)))
checked_dt.Columns.Add(New DataColumn("Price", GetType(decimal)))
dim i as integer
for i = 0 to datalist1.items.count-1
isitchecked = CType(Datalist1.Items(i).FindControl("mycheckbox"), CheckBox)
if isitchecked.checked then
pricelabel=CType(Datalist1.Items(i).FindControl("myprice"), label)
descriptionlabel=CType(Datalist1.Items(i).FindControl("mydescription"), label)
itemlabel=CType(Datalist1.Items(i).FindControl("myitem"), label)
runningtotal=runningtotal+ctype(pricelabel.text,decimal)
checked_dr = checked_dt.NewRow()
checked_dr(0)=itemlabel.text
checked_dr(1)=descriptionlabel.text
checked_dr(2)=ctype(pricelabel.text,decimal)
checked_dt.Rows.Add(checked_dr)
end if
next i
if checked_dt.rows.count>0 then
checked_dr = checked_dt.NewRow()
checked_dr(1)="Total : "
checked_dr(2)=runningtotal
checked_dt.Rows.Add(checked_dr)
Dim MyDataView as Dataview
MyDataView=New DataView(Checked_Dt)
datalist2.datasource=MyDataView
datalist2.databind
end if
End Sub
Sub Button2_Click(sender As Object, e As EventArgs)
Panel1.visible=true
Panel2.visible=false
End Sub</script>
<html>
<head>
</head>
<body>
<form runat="server">
<div align="center">
<asp:Panel id="Panel1" runat="server" Height="292px" Width="411px">
<div align="left">
<asp:DataList id="DataList1" runat="server" Width="402px" AlternatingItemStyle-BackColor="Gainsboro" HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" Font-Name="Verdana" CellPadding="3" GridLines="Both" BorderWidth="1px" BorderColor="Black" Font-Names="Verdana">
<AlternatingItemStyle backcolor="Gainsboro"></AlternatingItemStyle>
<ItemTemplate>
<asp:Label id="myitem" text='<%# DataBinder.Eval(Container.DataItem, "integerValue") %>' runat="server" /> <asp:Label id="mydescription" text='<%# DataBinder.Eval(Container.DataItem, "StringValue") %>' runat="server" />
<asp:checkbox id="mycheckbox" runat="server" />
Price:<asp:Label id="myprice" text='<%#DataBinder.Eval(Container.DataItem, "Price", "{0:c}")%>' runat="server" />
</ItemTemplate>
<HeaderStyle backcolor="#AAAADD"></HeaderStyle>
</asp:DataList>
<br />
</div>
<div align="center">
<br />
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Checkout"></asp:Button>
</div>
</asp:Panel>
</div>
<br />
<div align="center">
<asp:Panel id="Panel2" runat="server" Height="191px" Width="411px" BackColor="#FFE0C0" Visible="False">
<div align="left">
<asp:DataList id="DataList2" runat="server" Width="414px">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "PartNumber") %> <%# DataBinder.Eval(Container.DataItem, "Description") %> <%# DataBinder.Eval(Container.DataItem, "Price") %>
</ItemTemplate>
</asp:DataList>
<br />
<br />
<br />
</div>
<div align="center">
<asp:Button id="Button2" onclick="Button2_Click" runat="server" Text="Back"></asp:Button>
</div>
</asp:Panel>
</div>
</form>
</body>
</html>
copy and paste into the "ALL" pane in WebMatrix
you might want to check out how they did it in the commerce starter kit
HTH
0 comments:
Post a Comment