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

  1. Item1
  2. Item2
  3. Item3
  4. Item4

Each item when selected is bound to a corresponding page.

  1. Item1.aspx
  2. Item2.aspx
  3. Item3.aspx
  4. 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.

0
TigerKevENG
9/17/2008 12:47:38 PM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

3 Replies
1276 Views

Similar Articles

[PageSpeed] 47

for master page dropdownlist,  implement the following events like below.

 protected void test_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["index"] = test.SelectedIndex;
        Response.Redirect(test.SelectedValue);
       
    }
    protected void test_PreRender(object sender, EventArgs e)
    {
        if (Session["index"] != null)
            test.SelectedIndex = (int)Session["index"];
    }


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
9/17/2008 1:22:42 PM

Hi,

 Thanks, that resolved the issue of the DropDownList retaining the selected item, however its corresponding page does not fire now. In other words the chosen page does not load.

 Thanks.

0
TigerKevENG
9/19/2008 10:40:15 AM

 did u set autopostback propert to true in master page dropdownlist?

i am getting correctly. check whether seelcted index changed event is firing or not?

this is the master page i did.

 

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <table>
            <tr>
                This is master page
                <asp:DropDownList ID="test" runat="server" AutoPostBack="True" OnSelectedIndexChanged="test_SelectedIndexChanged" OnPreRender="test_PreRender">
                    <asp:ListItem Text="notupdating" Value="notupdating.aspx"></asp:ListItem>
                       <asp:ListItem Text="parentchildanddetails" Value="parentchildsanddetails.aspx"></asp:ListItem>
                </asp:DropDownList>
            </tr>
            <tr>
                <td>
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
        </asp:contentplaceholder>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
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;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
       

    }
    protected void test_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["index"] = test.SelectedIndex;
        Response.Redirect(test.SelectedValue);
        
    }
    protected void test_PreRender(object sender, EventArgs e)
    {
        if (Session["index"] != null)
            test.SelectedIndex = (int)Session["index"];
    }
}
//   and the content pages are just 2 pages. they don't have much code.

 


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
9/19/2008 10:48:46 AM
Reply:

Similar Artilces:

Setting DropDownList Selected Item from dbase SELECT
Hi! I've searched everywhere for the answer to this problem, but I can't seem to find the answer. I'm making an edit page for a user to edit their profile. One of the fields is a DropDownList containing a list of states (the states is populated from a database call to a lookup table). I want to match the state the user has in their profile to the appropriate state in the drop-down, and make that item selected. Unfortunately, I can't find any examples on how to do this. Also, since the drop-down control is within a repeater control (to populate the fields), it makes it even more diffi...

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...

HOW TO PROGRAMATICALLY SET THE SELECTED ITEM IN A DROPDOWNLIST WEB CONTROL
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...

How do I select an pre-selected dropdownlist item?
I have a dropdownlist for which I want to select the item previous selected, and the item id is a request.querystring item. How do I do that? dim selecteditem as string selecteditem = request.querystring(".....") dpTest.Items.FindByValue(selecteditem).Selected = True***********************Dinakar NethiLife is short. Enjoy it.*********************** Thanks !...

dropdownlist: select selected item during update
Hi, I have a datalist (databound) with notes ralated to persons. (Every note has one person). When I want to update a note, there is a drop downlist with al persons from the database (databound). The dropdownlist is created during the OnDataBind event of the datalist. But I want to select the previously selected person in the dropdownlist. (probably with dropdownlist.SelectedIndex). That is when the personID from the note is the same as the personID in the onDataBind of the dropdownlist. protected void dlLogboek_Ondatabind(object sender, DataListItemEventArgs e) { DropDownList ddlCpers...

How to set & show default value in dropdownlist from databound items (I am not asking the static -----select---- kind of item)
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005,  SQL Server 2005, Formview controls In a ASP.Net form I have 20 textoxes and 20 dropdownlists(ddl). All ddl(s) are databound and get the data from a single objectdatasource. All textbox and ddl support null values. Textbox is for entering a number and ddl (databound) is for selecting the unit (mm, cm, in, m3, oz, qt like these.). I am using the below code to achieve two things.(For each textbox and ddl has the corresponding codes like below.)Allowing the selection of ddl item also if it is not selected too, a default unit ite...

DropDownList Set Selected Item
The default item is never set in the dropdownlist. Even after the select list is created if I put a breakpoint on it I can see the selected value is correct. In the view the list is always set to the default item("Choose a Lead Category").// Set values for the dropdown lists.var leadCatList = new SelectList(      LeadInformationDataService.GetLeadCategories(),      "ID", "Description", newLeadInformation.LeadCategoryID);ViewData["LeadCategoryID"] = leadCatList; return View(newLeadInformation);<...

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? After you are done with loading the dropdownlist with data from the database.Thanks,MaxLet Me Google That For You! I know that, but where exactly is the event handler or method that I will need to put my code in? So you don't load it programatically. If thats the case, did you try Page_LoadT...

Setting selected item in dropdownlist
Hi, I know this has been covered a number of times and believe me I've tried but I can't make it work for the life of me. What I want is for, when the edit button in a datagrid is clicked and the dropdownlist appears, that the ddl is set to the same item as the field rather than the first in the list. so on and so forth. here is my code. Please help Dim TRDDLds As DataSet = New DataSet() Function TrainerList() As DataSet Dim sqlStr As String = "SELECT left(namelast,8)+' ,'+ left(namefirst,3) as contname FROM tbltrainers" Dim objTRAdapter As S...

Setting the selected item in a dropdownlist
I have been on this forum for quite a while looking for code that I can get to work for what I need. However, I have not found anything yet. I have a datagrid with a dropdownlist in each cell of the datagrid. Everything works fine up to this point. When I load the list of items into the dropdownlist I want the item in the list to be displayed that corresponds to the record in the dropdownlist. Here is what I have so far: Private Sub dgDefendants_itemCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgDefendants.ItemCreated...

How do I select item from DropDownList which contain only one item.
Hi guys,                   I have a two dropdownlist box in my Webform. If I select item from dropdownlist1 then, the items are added to the dropdownlist2 box according the values of dropdownlist box1. The problem is if i select the dropdownbox2 which contains only one item, it is not Autopostback. How do i solve the problem? Any one give me idea. I am newbie to C#. Thanks   Arun Insert a blank item into the DropDownListDropDownList.Items.Insert( 0, string.Empty ) Hi,In this case, the...

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...

Set static item selected style, when one of the dynamic items is selected
Hello, I have a menu with some parent items in the static menu. Now I would like this parentItems to be gray, when I am on one of the childpages ( on of the items in the dynamicMenu ). for example:here (screenshot below ) I am on the "doelstelling"-page, which is a subitem of "Bedrijfsinfo". Now, I would like the be able to set a certain style to "Bedrijfsinfo" when a user is on the doelstelling page, or one of the other subpages.  Is this possible?  Hi,Yes this is possible, however, you have to use the CSS Friendly menu. You can find ...

DropdownList
When I am using Drop Down List and populating it through code, the data is being populated.    But, when I select the desired item, whenever the page is posted back or whenever it is submitted, it is taking only the First Text/Value Item but not the one which I had selected.   Code is not refreshing the Dropdown Box but submission/postback event itself is resetting the Dropdownlist.   Kindly advise me what to do.  Regards, K.B. Narayana Sarma Dear KBN, Are you populating your list on the page load event. If yes, check for the "Page....

Web resources about - After selecting DropDownList Item, how to set DropDownList Item so that it corresponds to new selection. - asp.net.navigation-controls

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: 12/13/2015 8:04:29 AM