When to select items in a dropdownlist control?

I have a DropDownList that loads its data from a SqlDataSource. Right after the data has been loaded into the DropDownList, I want to programmaticaly go in and make a selection based a QueryString ID. So the question is, when do I start executing my code to make selection of the DropDownList items?
5/15/2007 8:15:35 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

10 Replies

Similar Articles

[PageSpeed] 23

After you are done with loading the dropdownlist with data from the database.
Let Me Google That For You!
5/15/2007 8:17:28 PM

I know that, but where exactly is the event handler or method that I will need to put my code in?

5/15/2007 8:31:40 PM
So you don't load it programatically. If thats the case, did you try Page_Load
Let Me Google That For You!
5/15/2007 8:40:58 PM

I have a DropDownList that loads its data from a SqlDataSource. Right after the data has been loaded into the DropDownList, I want to programmaticaly go in and make a selection based a QueryString ID.
To clarify my point again, the DropDownList control is bind to the sqlDataSource control that is why I said the data that fills the dropdownlist control is from a SqlDataSource. It is not through codebehind. However, what I wanted to do is right after the data is loaded into the dropdownlist control, I want to go in and select one of the items in the dropdownlist that is a match based on the QueryString ID.

5/16/2007 12:56:39 PM

I got that pal. What I was asking was that did you try setting the selected item in Page_Load. I tried what you have (but not with querystring parameter) and it worked fine.

Let Me Google That For You!
5/16/2007 1:23:47 PM

I tried the page load and it didn't work. I tried the databind, databound, Load of the dropdownlist control and none work.

5/16/2007 1:26:48 PM

Have a look at this post, especially the last reply.



Let Me Google That For You!
5/16/2007 1:50:57 PM

I tried his code sample and it's not working. The reason why it's not working is because the selection is made way before there is any data load into the dropdownlist control. His code will always generate a null value back since the selection occur in the Page_PreRender stage and not after the DDL has any data in it.

5/16/2007 3:47:19 PM

Bullpit: great link...fixed my problem.

5/17/2007 4:37:58 PM

Great!!! At least it helped someone

Let Me Google That For You!
5/17/2007 5:00:52 PM

Similar Artilces:

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

i have a datagrid and a dropdownlist (that has a value of male & female) as my edititemtemplate. i'd like to have the value of a cell(e.g female) serve as the default value of a dropdownlist after i click the edit button on a datagrid. any idea? try this with your controls Private Sub mygrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles mygrid.ItemDataBound If e.Item.ItemType = ListItemType.EditItem Then Dim mydropdown As DropdownList = CType(e.Item.FindControl("id of your control"), Dropdow...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

After selecting DropDownList Item, how to set DropDownList Item so that it corresponds to new selection.
Hi,  I'm having difficulty retaining DropDownList selected item so that it corresponds to the new page that is called when the item is selected. i.e DropDownList contains 4 Items Item1 Item2 Item3 Item4 Each item when selected is bound to a corresponding page. Item1.aspx Item2.aspx Item3.aspx Item4.aspx If the default page is Item1.aspx...if I select Item3 in the DropDownList, the page Navigates to the corresponding page - Item3.aspx.  I want the DropDownList to remain displaying Item3 and not the default Item.  Thank you. for master pag...

How to use Select case statement to select web form controls
Hi; I don't know why I can't conceptionalize  this but I want to take these if statements and put them in a select case. I am testing for multiple selection from several DDLs on my web form.   If DropDownList1.SelectedIndex > -1 And DropDownList2.SelectedIndex > 0 Then If Me.CheckBox1.Checked Then ObjectDataSource1.FilterExpression = "assignee = {0} AND assignor = {1}" Else ObjectDataSource5.FilterExpression = "assignee = {0} AND assignor = {1}" End If End If If DropDownList1.SelectedIndex > -1 And DropDownList3.SelectedIndex >...

how to populate a dropdownlist control and update the selected item in a gridview control
Hi friends help me with this ... Requirement: 1) i want to populate a dropdownlist(ddl) in a gridview when clicking the edit button of a perticular row by using gridview events and also update the selected item of the ddl to the database. 2) also i don't want to use sqldatasource controls i.e. we should take the help of only gridview events 3) DropDownList will be populated fom TableB: Actions taken: In page_load while binding the grid i m getting the error: Cannot perform '=' operation on System.Int32 and System.String  my fields and datatypes are as follows...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

how can i Fill the controls on web page by selecting value from dropdownlist control.
  Hi,  Currentlly i am working on a web application where i require to fill the web form with the selected item in a text box. for example i have dropdown control named supplier_name, and i want to fill all the other controls values from database on the form when i select name from that supplier_name box,i.e , if i select name1, then related to that name, its code,address ,city should appear on related text boxes. I have done the same in windows application with c# , but the problem with web application(asp.net) is that, when i select Supplier _ it...

how to call controls of web control form in coding of other forms?
hello everyone i have one problem i have created one webcontrol shoppingcart in which there are two labels one of qty and other of amt which are initially enable =falsenow on other page(aspx page) i have one txtbox of qty as txtqty i want tat as soon as user enters qty txtqty and clicks on add cart button it shd be display d value in lblqty of web control shopping cart make sure i m using datalist on aspx page so give me suggestions on tat basis and my coding is in vb. plz give ur suggestions as fast as possible. Neeti what do you mean by webcontrol.... it this user control or normal ...

How to access a control on a web form from anoter web form
hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it possible to access lbl1 from form2, change its text permenantly? thanks.   refer: http://dotnetslackers.com/Community/blogs/haissam/archive/2007/11/26/ways-to-pass-data-between-webforms.aspxSSNPlease remember to click "Mark as Answer" on the post that helps you. MinaSamy: hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it p...

Dynamic DropDownList Default Selected Item Does Not Select Default Item
I have some dynamic listbox code that creates a listbox based on information stored in a database. The database access works fine. The only issue is that when I use the lbNew.Items.FindByValue(...).Selected = True line, no default select is made. The listbox just defaults to the first item in the list.lbNew = New DropDownList ' Scans for the list source. ' If "values_table" returns the first character = '@', ' then a table is the datasource. strDataSourceTable = Nothing strDataSourceTable = objDataReader.Item("values_table") ' If there is a data list, display the item, else ig...

Select an item form the Collection of a DropDownList.
VB ASP.NET I need to select an item from the collection in a DropDownList from a TextBox, or from a dataset using a DataReader. Me.ddlQualifyDepth.SelectedItem.Value = Me.txtQualifyDepth.Text Perferd way, but the ddl is not being selected to the proper value from the list in the collection. Dim strSQL As String = "Select * FROM DiverInfo Where Diver='" & _ ddlDiver.SelectedItem.Value & "' " Dim myComm As New SqlClient.SqlCommand(strSQL, SqlConnection1) SqlConnection1.Open() ...

.Net Windows Control in Web Form
Hi all,How can I use a .Net windows control in a web form? I use object tag but it doesn't work and displays empty.Thanks in advance cheers Hi, you can check this article out: Hosting a Windows Control in a Web Form. This shows only how to host the control. If you want interaction with the client you can do this by setting the correct CAS (Code Access Security) settings on the client pc. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Workaround for non working Mark as answer buttons. Thanks guys for your replycheers...

Select Items in a DataList web Control
Hi all, I've inserted a button for selecting items in the ItemTemplate, but I cant create an event handler (when I double click on the button nothing happens). Can anyone help me? In order to make the button to select the row all you have to do is assign its CommandName attribute to 'select' If you also want to implement an event handler for it, then you need to create an event handler for the SelectedIndexChanged event of the grid, not the button event handlerBug [MCSD] Thank you! bye...

Web resources about - When to select items in a dropdownlist control? - asp.net.web-forms

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 11/29/2015 12:32:50 AM