473,769 Members | 4,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Repeater SubControl Dropdownlist not saving SelectedValue

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.asc x 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.asp x
--
<asp:repeater id="ProductsRep eater" runat="server">
<itemtemplate >
<tr bgcolor="#fffff f">
<td class="adminBla ck" valign="top">
<input type="hidden" runat="server" id="ProductID"
value='<%#DataB inder.Eval(Cont ainer.DataItem, "ProductID")%>' >
<asp:textbox runat="server" id="txtQty" cssclass="formT ext"
text='<%#DataBi nder.Eval(Conta iner.DataItem, "Quantity") %>' width="30px">
</asp:textbox><br >
<asp:button runat="server" id="updateQty"
commandargument ='<%#DataBinder .Eval(Container .DataItem, "ProductID" )%>'
commandname="up dateQty" text="Update" cssclass="submi tButton">
</asp:button>
</td>
<td class="adminBla ck"><a
href='http://www.mrchocolate .com/ecom/site/product.cfm?id= <%#DataBinder.E val(Container.D ataItem,
"ProductID")%>' ><%#DataBinder. Eval(Container. DataItem, "Name")%></a>
<uc1:productopt ionscontrol id="ProductOpti onsControl1"
runat="server"> </uc1:productopti onscontrol>
</td>
<td class="adminBla ck" align="right"
valign="top"><% #String.Format( "{0:c}", DataBinder.Eval (Container.Data Item,
"ItemPrice"))%> </td>
<td class="adminBla ck" align="right"
valign="top"><% #String.Format( "{0:c}", DataBinder.Eval (Container.Data Item,
"ItemTotal"))%> </td>
</tr>
</itemtemplate>
</asp:repeater>
--
OrderStatus.asp x.vb
--
--
Sub Page_Load:
--
Me.ProductsRepe ater.DataSource = shipAddress.Ord erItems
Me.ProductsRepe ater.DataBind()
'SelectedValue is reset back to 29 here ??? WHY ???

--
Sub ProductsRepeate r_ItemCreated:
--
ProductOptionsC ontrol1 = e.Item.FindCont rol("ProductOpt ionsControl1")

If Not IsNothing(Me.Pr oductOptionsCon trol1.OrderItem ) Then
Dim item As COrderItem = e.Item.DataItem

ProductOptionsC ontrol1.OrderIt em = item
'SelectedValue is valid at 27
End If

--
ProductOptionsC ontrol.ascx.vb:
--
Private m_orderItem As COrderItem
Friend Property OrderItem() As COrderItem
Get
If IsNothing(m_ord erItem) Then
m_orderItem = CType(Me.ViewSt ate.Item("m_ord erItem"), COrderItem)
End If
Return m_orderItem
End Get
Set(ByVal Value As COrderItem)
m_orderItem = Value
Me.ViewState.Ad d("m_orderItem" , m_orderItem)

If IsNothing(m_ord erItem) Then
m_orderItem.Loa dOrderAttribute s()

If Me.m_orderItem. Attributes.Coun t = 1 Then
Dim objProducts As New CStoreProducts
Dim arAttribs As ArrayList =
objProducts.Get ProductAttribut es(m_orderItem. ProductID)

Me.lblAttribute Name.Text = CType(arAttribs (0), CAttribute).Nam e

Me.ddlAttribute s.DataSource = CType(arAttribs (0),
CAttribute).Att ributeDetails
Me.ddlAttribute s.DataTextField = "Name_Price_Inf o"
Me.ddlAttribute s.DataValueFiel d = "UID"
Me.ddlAttribute s.DataBind()

'Example DDL Values are 29,27,28
'Selected Value is set to 27
Me.ddlAttribute s.SelectedValue = CType(CType(m_o rderItem.Attrib utes(0),
CAttribute).Att ributeDetails(0 ), CAttributeDetai l).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.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Nov 19 '05 #1
3 3316
It might be an issue with the ViewState. It doesn't seem to be saving. The
Controls EnableViewState =true, and also the Instance EnableViewState =true

Anyone?
Nov 19 '05 #2
On Fri, 28 Oct 2005 11:03:36 -0400, Ben Dewey wrote:
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.asc x 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.asp x
--
<asp:repeater id="ProductsRep eater" runat="server">
<itemtemplate >
<tr bgcolor="#fffff f">
<td class="adminBla ck" valign="top">
<input type="hidden" runat="server" id="ProductID"
value='<%#DataB inder.Eval(Cont ainer.DataItem, "ProductID")%>' >
<asp:textbox runat="server" id="txtQty" cssclass="formT ext"
text='<%#DataBi nder.Eval(Conta iner.DataItem, "Quantity") %>' width="30px">
</asp:textbox><br >
<asp:button runat="server" id="updateQty"
commandargument ='<%#DataBinder .Eval(Container .DataItem, "ProductID" )%>'
commandname="up dateQty" text="Update" cssclass="submi tButton">
</asp:button>
</td>
<td class="adminBla ck"><a
href='http://www.mrchocolate .com/ecom/site/product.cfm?id= <%#DataBinder.E val(Container.D ataItem,
"ProductID")%>' ><%#DataBinder. Eval(Container. DataItem, "Name")%></a>
<uc1:productopt ionscontrol id="ProductOpti onsControl1"
runat="server"> </uc1:productopti onscontrol>
</td>
<td class="adminBla ck" align="right"
valign="top"><% #String.Format( "{0:c}", DataBinder.Eval (Container.Data Item,
"ItemPrice"))%> </td>
<td class="adminBla ck" align="right"
valign="top"><% #String.Format( "{0:c}", DataBinder.Eval (Container.Data Item,
"ItemTotal"))%> </td>
</tr>
</itemtemplate>
</asp:repeater>
--
OrderStatus.asp x.vb
--
--
Sub Page_Load:
--
Me.ProductsRepe ater.DataSource = shipAddress.Ord erItems
Me.ProductsRepe ater.DataBind()
'SelectedValue is reset back to 29 here ??? WHY ???

--
Sub ProductsRepeate r_ItemCreated:
--
ProductOptionsC ontrol1 = e.Item.FindCont rol("ProductOpt ionsControl1")

If Not IsNothing(Me.Pr oductOptionsCon trol1.OrderItem ) Then
Dim item As COrderItem = e.Item.DataItem

ProductOptionsC ontrol1.OrderIt em = item
'SelectedValue is valid at 27
End If

--
ProductOptionsC ontrol.ascx.vb:
--
Private m_orderItem As COrderItem
Friend Property OrderItem() As COrderItem
Get
If IsNothing(m_ord erItem) Then
m_orderItem = CType(Me.ViewSt ate.Item("m_ord erItem"), COrderItem)
End If
Return m_orderItem
End Get
Set(ByVal Value As COrderItem)
m_orderItem = Value
Me.ViewState.Ad d("m_orderItem" , m_orderItem)

If IsNothing(m_ord erItem) Then
m_orderItem.Loa dOrderAttribute s()

If Me.m_orderItem. Attributes.Coun t = 1 Then
Dim objProducts As New CStoreProducts
Dim arAttribs As ArrayList =
objProducts.Get ProductAttribut es(m_orderItem. ProductID)

Me.lblAttribute Name.Text = CType(arAttribs (0), CAttribute).Nam e

Me.ddlAttribute s.DataSource = CType(arAttribs (0),
CAttribute).Att ributeDetails
Me.ddlAttribute s.DataTextField = "Name_Price_Inf o"
Me.ddlAttribute s.DataValueFiel d = "UID"
Me.ddlAttribute s.DataBind()

'Example DDL Values are 29,27,28
'Selected Value is set to 27
Me.ddlAttribute s.SelectedValue = CType(CType(m_o rderItem.Attrib utes(0),
CAttribute).Att ributeDetails(0 ), CAttributeDetai l).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.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Perhaps the problem is the postback behavior. you are rerendering
everything, everytime. Use the IsPostBack to control when you are
rebuilding the controls.
Nov 19 '05 #3
Well I figured out what the problem was. I was using the IsPostBack to
check and I wasn't rebinding the Repeater. The problem was that I was using
the OnItemCreated event for the repeater. I changed it to the
OnItemDataBound Event.

When I used the OnItemCreated event it Rebound the Nested Repeater on
everypost back

Essentially if you use nested repeaters and you are having an issue saving
the state. It probably a rebinding issue. Make sure you are checking the
IsPostBack and only Binding Once. Also make sure you are binding your
nested repeaters/controls on the OnDataBound Event, not the OnItemCreated
Event.
Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2428
by: kamaumalone | last post by:
I have a dropdownlist which lives inside of a repeater. The repeater accepts user input via textboxes and the aforementioned dropdownlist. The repeater accepts phone numbers and allows for an arbitrary number of empty rows to be added to it. So, if a user knew in advance that they wanted to add 3 phone numbers, they can type the nuber '3' in a textbox (outside the repeater) and click a button (also outside of a repeater), and 3 new empty ...
0
353
by: mrwoopey | last post by:
I did not find code for adding an event to dropdownlist in a repeater control posted anywhere. So, I am posting it for the next person (sorry if this seems obvious to you): '''''''''''''''''''' Private Sub MyRepeater_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles MyRepeater.ItemCreated Dim strValue As String
1
16911
by: Shaun Camilleri | last post by:
Hi all, I am creating a DropDownList in a RepeaterControl. After the Repeater is DataBound in the ItemCreated event (of the Repeater) I bind the DropDownList to a Table and then try to select one of its value. Here is the code: If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItem.AlternatingItem Then Dim ddl as DropDownList = Ctype(e.Item.FindControl("ddl"), DropDownList) With ddl
7
5488
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the Repeater control, I've placed DropDownLists and CheckBoxes. When the user has updated the information, he/he clicks the submit button which is outside the scope of the Repeater control.
1
2703
by: Jeremy | last post by:
Hello All, I have a Repeater which contains a Dynamic DropDownList within its itemtemplate. I know I have struggled with this before and I am pretty sure I had to save a bunch of crap manually to the viewstate, but does anyone know what would cause those DropDownList objects to clear out on postback. Is there a setting on the Repeater I am forgetting about? I tried tooling with EnableViewState but that did not work. The Repeater gets...
1
1449
by: mwhitlatch | last post by:
I have a repeater where the data is filtered by a param in the querystring. In the repeater I have a dropdown that needs to only show the data based upon the filter I set up in the datasource. I have a section below the dropdown where I can hardcode the filter param (item_id) but I need that hardcoded part to dynamically pass in the current items value. Thanks for any assistance <!-- Repeater --> <asp:Repeater ID="QueryStringRepeater"...
1
1613
by: Nitinkcv | last post by:
Hi, i have my button actually inside a repeater and it validates info from textboxes and ddl inside the repeater.. The prob is that i have "SELECT VALUE" chosen as the default value in my ddl. so while saving i want to check if the value in the DDL is not SELECT VALUE, then only it should save those.. so right now my code is private void Item_Created(Object Sender, RepeaterItemEventArgs e) {
3
2913
by: Mahathi | last post by:
Hi I have a small problem in maintaining the state of a check box. Please do me a favour by telling me the procedure how to do that. My requirement is that "I have to map some roles with that of the users of the project. I have used checkboxes for selecting the roles that a particular user has. For example, an adminstrator has all roles in an organisation. Similarly an Employee has limited roles. Here let us take administrator...
18
4985
by: Ben | last post by:
Hi, i dynamically feed a dropdownlist which value from 1 to 20. That dropdownlist is bound to field 'wa' (type nvarchar(4)) in 'mytable'. There are 4 records and the values of field 'wa' are: 2 3 1 4. All those values are contained in the list of items of the DD. In normal mode, the field 'wa' appears for each record with the right value. When i click on the Edit button, i get this error: "DropDownList1' has a SelectedValue which is...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.