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

Home Posts Topics Members FAQ

How to add a dropdownlist to a repeater - C#

Hi There,

I am developing a shopping cart web application in C#. Product
pricing for an item changes based on the weight of product purchased.
ie: 100g=$4.95, 200g=$7.95, etc. Pricing is different for each
product.

When viewing the cart, I would like the the user to have the ability
to select a different weight, specific to that item, which would then
modify the price of that cart item.

Question: How would I add a dropdownlist(sp ecific to each product) to
the repeater?

Thanks in advance,

Darren
Nov 18 '05 #1
7 6993
Darren,
Use the ItemCommand event of your repeater:
rpt.DataSource = dt;
rpt.ItemCommand += new RepeaterCommand EventHandler(rp t_ItemCommand);
rpt.DataBind();

or in VB.net, something like:

"Darren" <da****@yellowp encil.com> wrote in message
news:32******** *************** ***@posting.goo gle.com...
Hi There,

I am developing a shopping cart web application in C#. Product
pricing for an item changes based on the weight of product purchased.
ie: 100g=$4.95, 200g=$7.95, etc. Pricing is different for each
product.

When viewing the cart, I would like the the user to have the ability
to select a different weight, specific to that item, which would then
modify the price of that cart item.

Question: How would I add a dropdownlist(sp ecific to each product) to
the repeater?

Thanks in advance,

Darren

Nov 18 '05 #2

Darren,
Use the ItemCommand event of your repeater:
rpt.DataSource = dt;
rpt.ItemCommand += new RepeaterCommand EventHandler(rp t_ItemCommand);
rpt.DataBind();

or in VB.net, something like:
rpt.DataSource = dt
AddHandler rpt.ItemCommand , AddressOf rpt_ItemCommand
rpt.DataBind()

Then, in your rpt_ItemCommand function do something like:

private void rpt_ItemCommand (object source, RepeaterCommand EventArgs
e) {
if(e.Item.ItemT ype == ListItemType.Al ternatingItem ||
e.Item.ItemType == ListItemType.It em){
DropDownList weight =
(DropDownList)e .Item.FindContr ol("weight");
if(weight != null){
//bind weight here
}
}
}

that's assuming your dropdownlist has an id of "weight". You can access
e.Item.DataItem (cast it to the right type) and access the row information
to figure out what item type it is and thus figure out what to bind.

Karl

"Darren" <da****@yellowp encil.com> wrote in message
news:32******** *************** ***@posting.goo gle.com...
Hi There,

I am developing a shopping cart web application in C#. Product
pricing for an item changes based on the weight of product purchased.
ie: 100g=$4.95, 200g=$7.95, etc. Pricing is different for each
product.

When viewing the cart, I would like the the user to have the ability
to select a different weight, specific to that item, which would then
modify the price of that cart item.

Question: How would I add a dropdownlist(sp ecific to each product) to
the repeater?

Thanks in advance,

Darren

Nov 18 '05 #3
Hi Karl,

Thanks for your prompt reply.

I attempted to implement your example and I think my order of events is
a little off. I don't quite understand when and where the initial
specific datasource for that repeater item is databinded to the
dropdownlist. Hopefully I am being clear on my problem.

Page_Load - Databinds repeater to datasource
Below is the code for the repeater:

private void rptCart_ItemCom mand(object source,
System.Web.UI.W ebControls.Repe aterCommandEven tArgs e)
{

rptCart.ItemCom mand += new
RepeaterCommand EventHandler(rp tCart_ItemComma nd);
rptCart.DataBin d();

if(e.Item.ItemT ype == ListItemType.It em)
{
DropDownList ddnWeight = (DropDownList)e .Item.FindContr ol("ddnWeight") ;
if(ddnWeight !=null)
{
//Items will always be null as nothing is bound to that control.
}
}
When run, the dropdownlist is obviously empty. So to pose the question
once again, when, where and how would I bind the dropdownlist to a
subset datasource housing individual sizes for that specific product?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4
in page_load ->
datasource = xxx
itemCommand += new RepeaterEventHa nder(...)
databind()
in rptCart_ItemCom mand-->
if (e...)

)

in other words, put the rptCart.ItemCom mand += in the page_load
and don't rembind in the rptCart_ItemCom mand function.

Karl

"Darren" <da****@noemail .com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi Karl,

Thanks for your prompt reply.

I attempted to implement your example and I think my order of events is
a little off. I don't quite understand when and where the initial
specific datasource for that repeater item is databinded to the
dropdownlist. Hopefully I am being clear on my problem.

Page_Load - Databinds repeater to datasource
Below is the code for the repeater:

private void rptCart_ItemCom mand(object source,
System.Web.UI.W ebControls.Repe aterCommandEven tArgs e)
{

rptCart.ItemCom mand += new
RepeaterCommand EventHandler(rp tCart_ItemComma nd);
rptCart.DataBin d();

if(e.Item.ItemT ype == ListItemType.It em)
{
DropDownList ddnWeight = (DropDownList)e .Item.FindContr ol("ddnWeight") ;
if(ddnWeight !=null)
{
//Items will always be null as nothing is bound to that control.
}
}
When run, the dropdownlist is obviously empty. So to pose the question
once again, when, where and how would I bind the dropdownlist to a
subset datasource housing individual sizes for that specific product?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5
Thanks Karl,

One last question: Since each repeater item has a different weight/price
structure, am I to use a conventional loop to 1)obtain unique id for
that product 2)create datasource specifying unique weight/price records
and then bind to that products dropdown list in that repeater row?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #6
Not sure I follow the question. If you are simply asking what the best
structure to hold and bind the information...o ff the top of my head:

I'd have a single datatable with the following columns:
recordId int, displayName string, itemTypeId int

Then as you are binding, I'd get the item's typeId and filter the datatable
on itemTypeID column..if that makes _any_ sense..

Karl

"Darren" <da****@noemail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Thanks Karl,

One last question: Since each repeater item has a different weight/price
structure, am I to use a conventional loop to 1)obtain unique id for
that product 2)create datasource specifying unique weight/price records
and then bind to that products dropdown list in that repeater row?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #7
Perfect clarification. Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #8

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 ...
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
1
2157
by: Joe Gass | last post by:
I'd like to bind some xml to a dropdownlist <engines> <engine name="test1" id="1" /> <engine name="test2" id="2" /> </engines> If I do: ddlEngines.DataSource = xmlDoc.SelectNodes("/engines/engine")
4
5109
by: jjack100 | last post by:
I have a DropDownList that is nested inside a Repeater. The datasource of the DropDownList is declared in the aspx, not the codebehind. So we have this: <asp:Repeater ID="rptOptions" runat="server"> <ItemTemplate> <%# Eval("option_name") %> <asp:DropDownList ID="dlOptions" runat="server" DataSource='<%#
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
520
by: Eugene Anthony | last post by:
ModifyUserRegistration.aspx --------------------------- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModifyUserRegistration.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
0
1205
by: stretch73 | last post by:
I have a repeater control with a DropDownList in the header template. I am trying to make a database call and sort the results by the selectedIndex property of the drop down. The SelectedIndexChanged event is not getting fired, feel like I've tried everything. Repeater Code ********************************************************************************************************************************** <asp:Repeater...
3
2731
by: gsauns | last post by:
Hello, I have an ASP.NET app with a DropDownList on the page, which is bound to values from a table. I have a Repeater control on the page whose displayed data is dependent on the DropDownList value selected by the user. (The DataTextField is a Datetime concatenated with a string). On the Page_Load event, if it's not a postback, I would like the DropDownList to programmatically be set to the next occurring day in the DropDownList (the...
2
3749
by: MattB | last post by:
I have a (.Net 1.1) form with a Repeater and a DropDownList in the ItemTemplate. I programmatically make the DDL Autopostback = true at runtime based on the bound data. That works - I can see the postback happen appropriately. The DropDownList looks like this: <asp:DropDownList id="ddMultiQty" OnSelectedIndexChanged="ddMultiQty_SelectedIndexChanged" runat="server"></asp:DropDownList>
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,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.