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

how t orestore values back to drop down list afterpost back

hi , i m new to asp and leraning it...
i have only one page in which i take some values like name, dob and education degree. after post back i return to this page iteslf.. but the values in dropdown list is not tha what i hadve selected(coz it do not support viewstates).
is there any method to retrive the values back in drop down.
for text i m usoing like this.
<tr>
<td align="right" > Name : </td>
<td><input type=text id=txtName name=Name style="width: 300px" value="<%=request.Form("Name") %>" /></td>
</tr>

and for drop down i m using like this.......
<tr>
<td align="right"> Qualification : </td>
<td><select style="width: 300px" id= ddlDegree name=degree>
<option value="1" <%=BE %> >BE</option>
<option value="2" <%=BTECH %>>B TECH</option>
<option value="3" <%=MCA %>>MCA</option>
<option value="4" <%=MBA %>>MBA</option>
<option value="5" <%=MTECH %>>M TECH</option>
</select></td>
</tr>

<%
select case (request.Form("degree"))

case "1"
BE="selected"
case "2"
BTECH="selected"
case "3"
MCA="selected"
case "4"
MBA="selected"
case "5"
MTECH="selected"

end select
%>


but what if i have too many values in drop down.. is ther any better way to do this???
pls help..
thnx in advance.
Nov 30 '07 #1
4 1509
stepterr
157 100+
hi , i m new to asp and leraning it...
i have only one page in which i take some values like name, dob and education degree. after post back i return to this page iteslf.. but the values in dropdown list is not tha what i hadve selected(coz it do not support viewstates).
is there any method to retrive the values back in drop down.
for text i m usoing like this.
<tr>
<td align="right" > Name : </td>
<td><input type=text id=txtName name=Name style="width: 300px" value="<%=request.Form("Name") %>" /></td>
</tr>

and for drop down i m using like this.......
<tr>
<td align="right"> Qualification : </td>
<td><select style="width: 300px" id= ddlDegree name=degree>
<option value="1" <%=BE %> >BE</option>
<option value="2" <%=BTECH %>>B TECH</option>
<option value="3" <%=MCA %>>MCA</option>
<option value="4" <%=MBA %>>MBA</option>
<option value="5" <%=MTECH %>>M TECH</option>
</select></td>
</tr>

<%
select case (request.Form("degree"))

case "1"
BE="selected"
case "2"
BTECH="selected"
case "3"
MCA="selected"
case "4"
MBA="selected"
case "5"
MTECH="selected"

end select
%>


but what if i have too many values in drop down.. is ther any better way to do this???
pls help..
thnx in advance.



Typically what I do is include an if statement within my options. Such as:

<option value="1" <%if (request.Form("degree")=1)then%>selected<%end if%>>BE</option>
Nov 30 '07 #2
yaa i got it
thnx for help
Dec 3 '07 #3
thnx agian for ur help and i hpope you will chck it again

i have one concern in ths that
would it not create more complexity coz for first time i was checking for value only once and here i have to checjk for every item in select box..
my question was if i have less no of items in my dropdown than my code was ok but what if i have large no of items in that...

pls let me know if m concern is wrong or any better thing we can do....
thnx again :)
Dec 5 '07 #4
jhardman
3,406 Expert 2GB
Are you generating the dropdown list from an array or a db? if so, you can do something like this:
Expand|Select|Wrap|Line Numbers
  1. do until rs.eof %>
  2.    <option value="<%=rs("myFieldName")%>"
  3.    <% if request("thisInputName") = rs("myFieldName") then response.write "selected"%>
  4.    ><%=rs("myFieldName")%></option>
  5.    <%
  6.    rs.movenext
  7. loop
Let me know if this helps.

Jared
Dec 11 '07 #5

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

Similar topics

2
by: Chris Becker | last post by:
This is my attempt to rephrase a question I asked earlier that got no response. I suspect it was my poor/unplanned wording. Here is another attempt: I have a form with some drop down lists. I...
5
by: Rob Wire | last post by:
For the code below, how could I add an item in the drop down lists for both company and location to be an "All" selection that would send to the stored proc. spRptAttachments a value of "%" so...
2
by: R-D-C | last post by:
Hi, got a drop-down list on a windows form in VS.NET2003. In the form load when NOT a postback, we add four values to the drop-down list. These appear in Internet Explorer. When you click...
2
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the...
19
by: nazgulero | last post by:
Hello all, I wonder if anybody can give me a hint about what I have to do to get this working: I am creating a drop down box using the script below. The result is two text fields; now I want...
0
by: kajir | last post by:
Hi, I am new at using ASP.Net 2.0. I have various drop down lists on my master page. They refer to an SQL database. I also have a menu on the master page. I can select the values in the drop...
2
by: Jim Gregg | last post by:
Hello all, I am faced with some logic that I am unsure how to handle. Imagine that I am running a WMI query and I am outputting the data into a dynamically created ASP table control. Here is my...
3
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I...
1
by: bytenut | last post by:
I would like to display two field values in a combo after selecting from the list items... i.e. my drop-down shows two fields from a lookup, but when I select the item, only the first field value is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.