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

Home Posts Topics Members FAQ

Insert in DropDownList within Repeater

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_na me") %>

<asp:DropDownLi st ID="dlOptions" runat="server"
DataSource='<%#
GetOptionValues DL((int)DataBin der.Eval(Contai ner.DataItem,
"Item_ID")) %>'
DataTextField=" option_display" DataValueField= "option_value_i d">

</asp:DropDownLis t>

</ItemTemplate>
</asp:Repeater>
Then in the codebehind we have the function GetOptionValues DL which
returns a SqlDataReader which is databound to the DropDownList:
protected SqlDataReader GetOptionValues DL(int intItemID)
{
ProductsDB options = new ProductsDB();
SqlDataReader dr = options.GetOpti onValues(intIte mID);
return dr;
}
That works. But now I want to insert a listitem as the default in each
created dropdown. Since this has to be done after the dropdownlists are
bound, where can I do it? I got close with the PreRender event of the
DropDownLists:
protected void dlOptions_PreRe nder(object sender, System.EventArg s e)
{

DropDownList dlClone =
(DropDownList)r ptOptions.Items[0].FindControl("d lOptions");
dlClone.Items.I nsert(0, "Select");

}
The problem: this obviously only works for the first created
DropDownList (Items[0]) -- I haven't been able to come up with a way to
programmaticall y find each DropDownList in this manner.

Any ideas?

Thanks

Jack

Nov 19 '05 #1
4 5109
you can add default item to dropdownlist into way
1. after your dataset get fill add a datarow at position 0 in dataset.

2. after bind of dropdownlist add new listitem to dropdown list at 0th
position

Nov 19 '05 #2
Mahesh,

Yeah, I know that. The point of my question, though, was how to do that
in this specific scenario.

Nov 19 '05 #3
right now i have no code so i guide you how to do it

1. after your dataset get fill add a datarow at position 0 in dataset.
declare function that fill dataset for example
dataser binddrplist("qu ery")
{

add dummy row to dataset at 0th position

return dataset
}
now i think u should know when to call this function, on databound
event of repeater findcontrol and call the bind function.

2. after bind of dropdownlist add new listitem to dropdown list at 0th
position

on itemdatabount event of dropdownlist add dummy item to list at oth
position.

Nov 19 '05 #4
I really have a syntax problem, not a concept problem. I have already
inserted the item at the desired position, I just don't know how to
insert it for each ddlist in the scenario I have: 1) I'm not using a
dataset. 2) the code I posted illustrates the scenario. So, yes, I
know that in theory if you use a dataset and insert a dummy row or
insert a listitem after the list is databound you can create the
desired listitem -- but that doesn't really apply to my question.

Can anyone look at the code I posted and offer any advice?

Thanks

Nov 19 '05 #5

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
1327
by: JazzLover | last post by:
We have some javascript code that depends on the name of the dropdownlists to be the same as it parses them in an array, but within a repeater the webcontrols generate a uniqueid with ctl0: and some other junk prepended. Is there anyway we can prevent the dropdownlist from writing out its mangled name?
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
6
16618
by: Oscar | last post by:
I want to add items to a dropdownlist control within a Javascript eventhandler. This is what I code : var dd = document.getElementById("DropDownList1"); dd.Items.Add("1990"); dd.Items.Add("1991"); dd.Items.Add("1992");
3
3316
by: Ben Dewey | last post by:
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...
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
2107
by: Milsnips | last post by:
hi there, in ASP.NET 1.1 - debugging i can see that the dropdownlist item within the repeater is being populated and i do "droplist1.databind" but when the page loads there is no data. on top of page i declare "public DL as new DropDownList" What i'm doing is the following: on the page load, i create a new istance of "DL" and populate it with the data from database (1 db call), then when i
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">
5
3466
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration: default.aspx:
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...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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();...
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.