473,407 Members | 2,315 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,407 software developers and data experts.

selectedvalue not working..

Hi,

Currently i am using a dropdowlist which is actually databinded from a the datatbase. During my page load and by giving the !ispostback im binding the values into my DDL..

i get to this page from a previuos one using a query string Featureid=1. So after my DDL has been populated i use the following code:



if (Request.QueryString["FeatureId"] != null && Request.QueryString["FeatureId"].ToString() != "")
{
dropTopArea.SelectedValue = GetName(Convert.ToInt16(FeatureId));// Droptoparea is the id of the DDL.

}

where getname actually goes into the database and searches for the feature name using the FeatureId and returns the FeatureName. I debugged to check if it was reurning the right value and it was doing so.

However my DDL always loads up with the first element and not the one specified in the QueryString.

Could anyone help
Apr 26 '07 #1
1 1123
Frinavale
9,735 Expert Mod 8TB
Hi Nitinkcv,

You aren't setting the selected value properly.
I've provided a small snippet of code to help you get on track.
Its written in VB but the same concepts apply to your C# application.

Expand|Select|Wrap|Line Numbers
  1. Public Shared Sub SetDdlSelectedValue(ByVal theList As System.Web.UI.WebControls.ListControl, ByVal selectedValue As String)
  2.    'Sub Description:
  3.    '   This sub is responsible for setting the selected value in the dropDownList provided.
  4.    'Parameters:
  5.    '   theList: the DropDownList
  6.    '   SelectedValue: the value to be selected in the dropDownList
  7.    'Retrun Value:
  8.    '   Although this doesn't return anything, the dropDownList passed in is passed in by its reference pointer...
  9.    '   which means it is modified to contain a highlighted value of that supplied
  10.  
  11.    Try
  12.        theList.ClearSelection()
  13.        theList.Items.FindByText(selectedValue).Selected = True
  14.    Catch ex As Exception
  15.  
  16.    End Try
  17.  
  18.  End Sub
  19.  
  20.  
Please note that the System.Web.UI.WebControls.ListControl is the base class for a DropDownList. Therefore you can pass this function a dropDownList and the selection will still be set.

Hope this helps you!

-Frinny
Apr 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: MrMike | last post by:
Hello. I have the following code on an ASP webform that formats a dropdownlist named ddlCustomer... 'Populate ddlCustomer Dim CustAdapter As New SqlDataAdapter("SELECT * FROM lkup_Customers",...
6
by: Mike Caputo | last post by:
Shouldn't I be able to set the selected item of a combobox with the SelectedValue property? The ComboBox has four items, the values are 1 through 4. Here's an example of what I'm trying to do: ...
1
by: Gary Shell | last post by:
I have a pair of combo boxes on a form. Both have their SelectedValue property bound to a column on a table called "Input_Output". One column is called "Class" and the second is called "SubClass"....
8
by: CK | last post by:
Hi All, I have a class and one property is an Enum. I am trying to persist the DropDownList.SelectedValue to the class property. I am using job.ExpRelated =...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
1
by: clickon | last post by:
Forget about the controlParameter for the moment, for testing purposes i have created the following Markup: <asp:Table ID="tblSelectRoute" runat="server" CssClass="asp-table"> <asp:TableRow>...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
0
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the...
1
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I generally work on web apps, but I am dealing with a Winform right now and may be missing something really basic. I have a combobox and I would like to know what value has been selected....
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...

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.