473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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_name") %>

<asp:DropDownList ID="dlOptions" runat="server"
DataSource='<%#
GetOptionValuesDL((int)DataBinder.Eval(Container.D ataItem,
"Item_ID"))%>'
DataTextField="option_display" DataValueField="option_value_id">

</asp:DropDownList>

</ItemTemplate>
</asp:Repeater>
Then in the codebehind we have the function GetOptionValuesDL which
returns a SqlDataReader which is databound to the DropDownList:
protected SqlDataReader GetOptionValuesDL(int intItemID)
{
ProductsDB options = new ProductsDB();
SqlDataReader dr = options.GetOptionValues(intItemID);
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_PreRender(object sender, System.EventArgs e)
{

DropDownList dlClone =
(DropDownList)rptOptions.Items[0].FindControl("dlOptions");
dlClone.Items.Insert(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
programmatically find each DropDownList in this manner.

Any ideas?

Thanks

Jack

Nov 19 '05 #1
4 5088
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("query")
{

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
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...
1
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...
1
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...
6
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");...
3
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...
1
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...
1
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...
1
by: Eugene Anthony | last post by:
ModifyUserRegistration.aspx --------------------------- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModifyUserRegistration.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC...
5
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:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.