Kanixooliaa
New Member
How can I set a default value to a DropDownList when its DataSource is a DataTable?<BR><BR>'open the connection and execute the command<BR> objConnect.Open()<BR> Dim objDataReader As OleDbDataReader<BR> objDataReader = objCommand.ExecuteReader()<BR> dropdownID.DataSource = objDataReader<BR> dropdownID.DataBind()<BR> objConnect.Close() 'then close the connection<BR> dropdownID.Items.Insert(0, "------- Please Choose -------")<BR> dropdownID.SelectedIndex = 0<BR> dropdownID.SelectedItem.Value = http://aspmessageboard.com/archive/index.php/""Mark<BR><BR>Your suggestion would usually work, but this DropDownList is within an EditItemTemplate of a DataList, so I can't actually reference it as you've suggested because its a dynamically created control. <BR><BR>To populate it I create a global DataTable and assign this as the List's data source (see knowledge article http://www.4guysfromrolla.com/webtech/050801-1.shtml), but I can't find a way of setting a default selection such as '-- Make a Selection --'<BR><BR>HELP!!Sorry, that should have been http://www.4guysfromrolla.com/webtech/050801-1.shtmlThats a bit trickier alright! Not quite sure to be honest did you try a search on google groups?<BR>http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&group=microsoft.public.dotnet.framework.aspnetI've searched on several techy sites...<BR><BR>At the moment, the DropDownList re-populates a second DropDownList with data when the OnSelectedIndexChanged event is triggered in a Category -> Sub-category relationship. This works fine.<BR><BR>When the page is re-loaded, the master DropDownList does not remember the selected item because its a dynamically generated control.<BR><BR>The OnSelectedIndexChanged event provides me with the value of the selected item, and this is passed to a Stored Procedure as a parameter to fetch the correct Sub-category data.<BR><BR>The must be a way of using the selecteditem.value to manipulate the order of the data put into the global DataTable (Remember the global DataTable is the data source of the main DropDownList).<BR><BR>HELP!