B
Ben Dewey
Hey everyone,
I have a wierd issue i can't seem to find out whats going on. I have a
Control for a Shopping Cart Merchant Page called OrderStatus.ascx Inside
that control there is a Repeater with the Products that were ordered on the
ItemCreated event of the repeater i set a property of an options control
within the repeater. The Options control sets a DropDownList and then sets
a SelectedValue.
The Selected Value prop is correct after set, when you get back to the
itemCreated sub it is set there as well, But when it gets out of the
DataBind function and back to the PageLoad sub this value is cleared. Any
idea why anyone?
Here is the code:
---------------------------------------
--
OrderStatus.aspx
--
<asp:repeater id="ProductsRepeater" runat="server">
<itemtemplate>
<tr bgcolor="#ffffff">
<td class="adminBlack" valign="top">
<input type="hidden" runat="server" id="ProductID"
value='<%#DataBinder.Eval(Container.DataItem, "ProductID")%>'>
<asp:textbox runat="server" id="txtQty" cssclass="formText"
text='<%#DataBinder.Eval(Container.DataItem, "Quantity")%>' width="30px">
</asp:textbox><br>
<asp:button runat="server" id="updateQty"
commandargument='<%#DataBinder.Eval(Container.DataItem, "ProductID")%>'
commandname="updateQty" text="Update" cssclass="submitButton">
</asp:button>
</td>
<td class="adminBlack"><a
href='http://www.mrchocolate.com/ecom/site/product.cfm?id=<%#DataBinder.Eval(Container.DataItem,
"ProductID")%>'><%#DataBinder.Eval(Container.DataItem, "Name")%></a>
<uc1roductoptionscontrol id="ProductOptionsControl1"
runat="server"></uc1roductoptionscontrol>
</td>
<td class="adminBlack" align="right"
valign="top"><%#String.Format("{0:c}", DataBinder.Eval(Container.DataItem,
"ItemPrice"))%></td>
<td class="adminBlack" align="right"
valign="top"><%#String.Format("{0:c}", DataBinder.Eval(Container.DataItem,
"ItemTotal"))%></td>
</tr>
</itemtemplate>
</asp:repeater>
--
OrderStatus.aspx.vb
--
--
Sub Page_Load:
--
Me.ProductsRepeater.DataSource = shipAddress.OrderItems
Me.ProductsRepeater.DataBind()
'SelectedValue is reset back to 29 here ??? WHY ???
--
Sub ProductsRepeater_ItemCreated:
--
ProductOptionsControl1 = e.Item.FindControl("ProductOptionsControl1")
If Not IsNothing(Me.ProductOptionsControl1.OrderItem) Then
Dim item As COrderItem = e.Item.DataItem
ProductOptionsControl1.OrderItem = item
'SelectedValue is valid at 27
End If
--
ProductOptionsControl.ascx.vb:
--
Private m_orderItem As COrderItem
Friend Property OrderItem() As COrderItem
Get
If IsNothing(m_orderItem) Then
m_orderItem = CType(Me.ViewState.Item("m_orderItem"), COrderItem)
End If
Return m_orderItem
End Get
Set(ByVal Value As COrderItem)
m_orderItem = Value
Me.ViewState.Add("m_orderItem", m_orderItem)
If IsNothing(m_orderItem) Then
m_orderItem.LoadOrderAttributes()
If Me.m_orderItem.Attributes.Count = 1 Then
Dim objProducts As New CStoreProducts
Dim arAttribs As ArrayList =
objProducts.GetProductAttributes(m_orderItem.ProductID)
Me.lblAttributeName.Text = CType(arAttribs(0), CAttribute).Name
Me.ddlAttributes.DataSource = CType(arAttribs(0),
CAttribute).AttributeDetails
Me.ddlAttributes.DataTextField = "Name_Price_Info"
Me.ddlAttributes.DataValueField = "UID"
Me.ddlAttributes.DataBind()
'Example DDL Values are 29,27,28
'Selected Value is set to 27
Me.ddlAttributes.SelectedValue = CType(CType(m_orderItem.Attributes(0),
CAttribute).AttributeDetails(0), CAttributeDetail).UID.ToString
'SelectedValue is valid at 27
Else
Me.Visible = False
End If
End If
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
I have a wierd issue i can't seem to find out whats going on. I have a
Control for a Shopping Cart Merchant Page called OrderStatus.ascx Inside
that control there is a Repeater with the Products that were ordered on the
ItemCreated event of the repeater i set a property of an options control
within the repeater. The Options control sets a DropDownList and then sets
a SelectedValue.
The Selected Value prop is correct after set, when you get back to the
itemCreated sub it is set there as well, But when it gets out of the
DataBind function and back to the PageLoad sub this value is cleared. Any
idea why anyone?
Here is the code:
---------------------------------------
--
OrderStatus.aspx
--
<asp:repeater id="ProductsRepeater" runat="server">
<itemtemplate>
<tr bgcolor="#ffffff">
<td class="adminBlack" valign="top">
<input type="hidden" runat="server" id="ProductID"
value='<%#DataBinder.Eval(Container.DataItem, "ProductID")%>'>
<asp:textbox runat="server" id="txtQty" cssclass="formText"
text='<%#DataBinder.Eval(Container.DataItem, "Quantity")%>' width="30px">
</asp:textbox><br>
<asp:button runat="server" id="updateQty"
commandargument='<%#DataBinder.Eval(Container.DataItem, "ProductID")%>'
commandname="updateQty" text="Update" cssclass="submitButton">
</asp:button>
</td>
<td class="adminBlack"><a
href='http://www.mrchocolate.com/ecom/site/product.cfm?id=<%#DataBinder.Eval(Container.DataItem,
"ProductID")%>'><%#DataBinder.Eval(Container.DataItem, "Name")%></a>
<uc1roductoptionscontrol id="ProductOptionsControl1"
runat="server"></uc1roductoptionscontrol>
</td>
<td class="adminBlack" align="right"
valign="top"><%#String.Format("{0:c}", DataBinder.Eval(Container.DataItem,
"ItemPrice"))%></td>
<td class="adminBlack" align="right"
valign="top"><%#String.Format("{0:c}", DataBinder.Eval(Container.DataItem,
"ItemTotal"))%></td>
</tr>
</itemtemplate>
</asp:repeater>
--
OrderStatus.aspx.vb
--
--
Sub Page_Load:
--
Me.ProductsRepeater.DataSource = shipAddress.OrderItems
Me.ProductsRepeater.DataBind()
'SelectedValue is reset back to 29 here ??? WHY ???
--
Sub ProductsRepeater_ItemCreated:
--
ProductOptionsControl1 = e.Item.FindControl("ProductOptionsControl1")
If Not IsNothing(Me.ProductOptionsControl1.OrderItem) Then
Dim item As COrderItem = e.Item.DataItem
ProductOptionsControl1.OrderItem = item
'SelectedValue is valid at 27
End If
--
ProductOptionsControl.ascx.vb:
--
Private m_orderItem As COrderItem
Friend Property OrderItem() As COrderItem
Get
If IsNothing(m_orderItem) Then
m_orderItem = CType(Me.ViewState.Item("m_orderItem"), COrderItem)
End If
Return m_orderItem
End Get
Set(ByVal Value As COrderItem)
m_orderItem = Value
Me.ViewState.Add("m_orderItem", m_orderItem)
If IsNothing(m_orderItem) Then
m_orderItem.LoadOrderAttributes()
If Me.m_orderItem.Attributes.Count = 1 Then
Dim objProducts As New CStoreProducts
Dim arAttribs As ArrayList =
objProducts.GetProductAttributes(m_orderItem.ProductID)
Me.lblAttributeName.Text = CType(arAttribs(0), CAttribute).Name
Me.ddlAttributes.DataSource = CType(arAttribs(0),
CAttribute).AttributeDetails
Me.ddlAttributes.DataTextField = "Name_Price_Info"
Me.ddlAttributes.DataValueField = "UID"
Me.ddlAttributes.DataBind()
'Example DDL Values are 29,27,28
'Selected Value is set to 27
Me.ddlAttributes.SelectedValue = CType(CType(m_orderItem.Attributes(0),
CAttribute).AttributeDetails(0), CAttributeDetail).UID.ToString
'SelectedValue is valid at 27
Else
Me.Visible = False
End If
End If
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub