473,657 Members | 2,515 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 onselectedindex changed 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 onselectedidexc hanged 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 1521
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.i tems.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.i tems.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
onselectedindex changed(nothing ,nothing)
end if

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

br***********@h ighstream.net wrote in news:1115398279 .674704.25720
@f14g2000cwb.go oglegroups.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 onselectedindex changed 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 onselectedidexc hanged 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.D ataBind()
DropDownList1.I tems.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.D ataBind()
DropDownList1.I tems.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
3414
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 being dependent on the value of the first. My DropDownList control definitions look like this: <asp:dropdownlist id="ddlLocCty" runat="server" CssClass="SmlBox" AutoPostback="True" CausesValidation="False"></asp:dropdownlist> <asp:dropdownlist...
12
2779
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 Description"></asp:BoundColumn> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" "> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TypeOption") %>' /> <asp:label runat="server" ID="LlbTypeOption" Visible=False...
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 in the database. <asp:DropDownList id="ComboTipoPartita" runat="server" DataValueField="IDTipoPartita" DataTextField="DescrizioneTipoPartita" DataSource="<% BindComboTipoPartita() %>"
1
1991
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 OnItemDataBound I can fill it but it is impossible for me to load the right selectedItem.Value , infact looking at the html page produced by the server I've this strange code : <select name="MyDataCampi:_ctl1:ComboTipoPartita"...
10
10736
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 = true; Where endTime is a string containing "15".
4
2008
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, when the datagrid enters it's own OnPreRender, the selected index has reverted to zero. I created a debug version of the dropdown list which inherited from dropdownlist and overrode the selected index property to trace.write whenever it was...
0
1269
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 first dropdownlist. Now, I'm working with ASP.net 2.0 and the gridview. I apply the same method but the second dropdownlist don't shows the rows filtered, it shows the rows filtered when the gridview was loaded for the first time.
3
10572
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 second of which resides within an UpdatePanel control which responds to a change in the first DropDownList. I also have a hidden button nested inside the UpdatePanel to force a postback via JS. The user uses these two DropDownList controls to create...
1
4923
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 time. The problem is that when an item has been removed from the lookup table, and a user wants to retrieve a record that used the deleted item, the following error occurs: 'ddlAssignedTo' has a SelectedValue which is invalid because it...
6
4269
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 boxes are generating a postback.here is a code . protected void Page_Load(object sender, EventArgs e) { int selected_question = (int)Session; if (!Page.IsPostBack) { display_blueprint(); string...
0
8844
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
8518
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
8621
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...
0
5643
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
4173
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...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
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.