473,503 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dropdownlist problem

Hi all,

Please forgive if this has been answered before, but I haven't been
able to find the solution. I'm working on a project for school that
will use a dropdownlist populated by data from a database. The
dropdownlist will use the onselectedindexchanged event to trigger a
subroutine that will populate a datagrid based on the selected item in
the dropdownlist.

I've got the dropdownlist and the sub to handle populating the
datagrid, but one other aspect of the problem is that all items are to
fire the event that loads the datagrid. The challenge is to have the
event fire when the first item is selected. But by default, the first
item of a datagrid is already selected and clicking on it won't fire
the onselectedidexchanged event. According to the instructor, "this
can be easily accomplished with one line of code, but it was not
covered during the course."

I've been scanning the web and all my books, but can't figure it out.
Any suggestions would be most appreciated...

Nov 19 '05 #1
6 1512
Well, I found a workaround...

if not page.ispostback then add a new item at index 0 with a text value
= "Select...", which becomes the default selected item. Next time
around, I dropdownlist1.items.removeat(0) if the text="Select..."

While this works, it's not the "one line of code" solution it's
supposed to be. I'm still hopeful for that easy one line solution...

Nov 19 '05 #2
I assume that you are populating the dropdown from a database with an SQL
statement. We use a union on our select something like

Select
0 as UserID,
" " as Display Name
Union
Select
....... Whatever your current SQL is

This creates a blank line at the beginning of the DropDown list.

I would be interested in the one line of code as well.

Steven

"br***********@highstream.net" wrote:
Well, I found a workaround...

if not page.ispostback then add a new item at index 0 with a text value
= "Select...", which becomes the default selected item. Next time
around, I dropdownlist1.items.removeat(0) if the text="Select..."

While this works, it's not the "one line of code" solution it's
supposed to be. I'm still hopeful for that easy one line solution...

Nov 19 '05 #3
This may not be the solution but what I do
in the page load

if not page.ispostback
.....
do the drop down list databinding
onselectedindexchanged(nothing,nothing)
end if

This is done in one line since the rest should be doing anways
James

br***********@highstream.net wrote in news:1115398279.674704.25720
@f14g2000cwb.googlegroups.com:
Hi all,

Please forgive if this has been answered before, but I haven't been
able to find the solution. I'm working on a project for school that
will use a dropdownlist populated by data from a database. The
dropdownlist will use the onselectedindexchanged event to trigger a
subroutine that will populate a datagrid based on the selected item in
the dropdownlist.

I've got the dropdownlist and the sub to handle populating the
datagrid, but one other aspect of the problem is that all items are to
fire the event that loads the datagrid. The challenge is to have the
event fire when the first item is selected. But by default, the first
item of a datagrid is already selected and clicking on it won't fire
the onselectedidexchanged event. According to the instructor, "this
can be easily accomplished with one line of code, but it was not
covered during the course."

I've been scanning the web and all my books, but can't figure it out.
Any suggestions would be most appreciated...


Nov 19 '05 #4
EJD
I may have misunderstood the question, but this might help. I have a
dropdownlist in a user control that displays a number of items, and
when an item is selected it redirects to a page that has several
datagrids based on the choice.
If(!IsPostBack)
{
// gets values from database
PopulateDDL():
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, "Please select a
service...");
}
This add a dummy value at the top that means all of the other values
will cause a postback and whatever action I want. It's not elegant,
but it works. HTH.

Eric

Nov 19 '05 #5
EJD
I may have misunderstood the question, but this might help. I have a
dropdownlist in a user control that displays a number of items, and
when an item is selected it redirects to a page that has several
datagrids based on the choice.
If(!IsPostBack)
{
// gets values from database
PopulateDDL():
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, "Please select a
service...");
}
This add a dummy value at the top that means all of the other values
will cause a postback and whatever action I want. It's not elegant,
but it works. HTH.

Eric

Nov 19 '05 #6
Thanks for the help!

I implemented a solution where if not page.ispostback, I added a blank
line at the top, forcing the user to make a selection. Then, if
page.ispostback, I simply eliminate the blank line. I have a feeling
that this is what the instructor was looking for, so that's what I'm
going with. :)

I'll keep you posted if the solution is different.

Brian

Nov 19 '05 #7

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

Similar topics

2
3393
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second...
12
2760
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
2
467
by: Antonio D'Ottavio | last post by:
Good Morning, In my web page I've a datalist that is sourced by a database, the problem is that I want that one of the column of the datalist contain a dropdownbox that also is sourced by a table...
1
1967
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
10
10710
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
4
2000
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
0
1263
by: Juanjo | last post by:
Hi, Before, I was working with Asp.net 1.0 and datagrid. I posted a question for this issue. The solution of this problem is load the second dropdownlist on the selectedindexchanged event of the...
3
10560
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
1
4908
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over...
6
4260
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
0
7203
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
7281
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,...
0
7334
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...
1
6993
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
5579
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,...
0
4675
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...
0
3168
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...
0
1514
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 ...
1
737
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.