473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how t orestore values back to drop down list afterpost back

19 New Member
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="<%=reque st.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 1516
stepterr
157 New Member
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="<%=reque st.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<%en d if%>>BE</option>
Nov 30 '07 #2
gotonagle
19 New Member
yaa i got it
thnx for help
Dec 3 '07 #3
gotonagle
19 New Member
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 Recognized Expert Specialist
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
3620
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 would like the user to be able to start filling in the form, then get to one of the dropdown lists (ex: Service Type) and realize that the dropdown list does not contain the entry that they need. So next to the Service Type drop down list is a...
5
2238
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 that it would bring back all attachments at all companies or all locations at a company? Thank you, Rob. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then
2
1396
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 a button on the form, the value selected in the drop-down is supposed to be put in a label's Text property. However, when you click the button, the page refreshes and all of the values from the drop-down list are
2
12353
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 users need not enter values in all the controls. they can leave the textbox blank, and select values from one drop down, or any other combinations. I am trying to pass values with the help of session variables. But I have multiple if else...
19
9074
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 to pass those values, which come from the drop down box, to the next page. The next page should then simply look like this:
0
1852
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 down list and generate reports using Reporting services and parameters on the default page. Now I want to create another kind of report on another page using the same values in the drop down lists. But, when I click on a menu item to change...
2
1789
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 code that does this. I have left out the portion that connects to my server and the query, but this should be enough to show what I am doing. Basically it is a web page that queries SMS for clients in a certain collection, then outputs the name...
3
5883
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 analyze each word and rebuild the text string as a combination of correct text (not misspelled) and a drop down list offering suggestions in place of any misspelled words. Pretty common stuff using pspell. I display the new string so that the user...
1
2345
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 shown in the combo text area (at the top)... (bound field is invisible) e.g. Currently seeing (standard behavior) drop-down | 1 drop-down | 2 drop-down | 3
0
8413
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
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
8513
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
5642
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
2742
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
1733
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.