How to retain and get the selected value of the drop down upon post back

Hi

I have a form view. Inside the formview I have a drop down. I did not bind the drop down with the ODS. Instead I do it manually on the code behind. If the user selects a value I display a textbox beside the drop down and allow the user to enter the value. Upon onblur event of the textbox I do a postback and in the page load i check whethere the page has been posted. If so I add this value to the datatable and once again bind it to the combo box and set the selected value to the text box value.

   If the user clicks the save button and when I look for the selected value it says Nothing.

What could be the problem. Please help me in this regard.

Thanks a lot in advance. 

 

 

 

-1
janakiraman
7/11/2008 12:00:51 PM
asp.net.presentation-controls 72751 articles. 2 followers. Follow

6 Replies
504 Views

Similar Articles

[PageSpeed] 20

SelectedValue could be found on the same page. If there is a postback, it will be gone. Could you show your code? 

-1
webberman
7/11/2008 1:02:06 PM

Please post your code so we can further assist you, but it seems that the value isn't being passed.


~~ Believe in Science, not religion. Science will always progress, religions will always collapse. ~~
-1
TheDirtyBird
7/11/2008 1:34:49 PM

Try to user below code:

 

<asp:dropdownlist Id="1"  Runat="Server" SelectedValue='<% Eval("Some data")%' DataTextField="Some Data Column" Sqldatasource="Sqldatasource1" />

I guess this will help you.

Here Selected value attribute will help you show the selected value of the user and datatext will help you show the dropdown data.....it may or may in your datasource dont bother about it 


Thanks
Parth
visit for some interesting articals at
www.parthrawal.blogspot.com
Mark as Answer if it helps you
-1
parthrawal
7/11/2008 4:08:28 PM

In aspx page I have the following code

<asp:DropDownList ID="ddlSource" SkinID="DropDownNormalText" runat="server">
</asp:DropDownList>

In the VB page I have

Page Load

ChangeFormViewModeByUserRole

 If Me.IsPostBack And iTagID > ZERO Then
        sValue = CType(Me.fvTags.FindControl("txtSource"), TextBox).Text
        If (CType(Me.fvTags.FindControl("txtSource"), TextBox).Visible = True) AndAlso (sValue <> "") Then
            Dim dt As DataTable = oTagNameMaintenance.GetTagSourcefromTags
            AddRowToReturnTable(dt, sValue)
            With CType(Me.fvTags.FindControl("ddlSource"), DropDownList)
                .DataSource = dt
                .DataBind()
                .SelectedValue = sValue
            End With
        End If
        CType(Me.fvTags.FindControl("txtSource"), TextBox).Text = ""

End If

End Page load

Region Function

 Private Sub AssignDataForSourceComboBox()
        Dim dt As DataTable = oTagNameMaintenance.GetTagSourcefromTags
        With CType(Me.fvTags.FindControl("ddlSource"), DropDownList)
            .DataSource = dt
            .DataTextField = "TagSource"
            .DataValueField = "TagSource"
            .DataBind()
        End With

    End Sub

 Private Sub ChangeFormViewModeByUserRole()

        If MasterPage.HasService("ReadWrite", sRedirectURL, oUser) Then
            If iTagID > ZERO Then
                fvTags.ChangeMode(FormViewMode.Edit)
                AssignDataForSourceComboBox()
                Me.pnlUserInfo.Visible = True
            ElseIf iTagID = MINUS_ONE Then
                fvTags.ChangeMode(FormViewMode.Insert)
                AssignDataForSourceComboBox()
                Me.pnlUserInfo.Visible = False
            End If
        Else
            Me.lnkNew.Visible = False
            If iTagID > ZERO Then
                fvTags.ChangeMode(FormViewMode.ReadOnly)
                Me.pnlUserInfo.Visible = True
                CType(fvTags.FindControl("lnkExit"), HyperLink).NavigateUrl = sRedirectURL & "?ExpandResult=Y"
            End If
        End If

  Private Sub odsTagDetails_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles odsTagDetails.Updating

            e.InputParameters("TagSource") = CType(Me.fvTags.Row.FindControl("ddlSource"), DropDownList).SelectedValue
      
    End Sub

 

While updating the ODS this is where I get the selected value for the drop down. I get Nothing here.

Please help me in this regard.

Thanks a lot for all your suggestions.

Thanks

Janakiraman 

 

 

 

1
janakiraman
7/12/2008 7:21:19 AM

HI janakiraman ,

janakiraman:

Page Load

ChangeFormViewModeByUserRole

 If Me.IsPostBack And iTagID > ZERO Then
        sValue = CType(Me.fvTags.FindControl("txtSource"), TextBox).Text
        If (CType(Me.fvTags.FindControl("txtSource"), TextBox).Visible = True) AndAlso (sValue <> "") Then
            Dim dt As DataTable = oTagNameMaintenance.GetTagSourcefromTags
            AddRowToReturnTable(dt, sValue)
            With CType(Me.fvTags.FindControl("ddlSource"), DropDownList)
                .DataSource = dt
                .DataBind()
                .SelectedValue = sValue
            End With
        End If
        CType(Me.fvTags.FindControl("txtSource"), TextBox).Text = ""

End If

End Page load

Please make sure you do not re-bind the DropDownlist before the method odsTagDetails_Updating execute , if ddl is rebound , the selectedvalue will be refreshed.

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
1
Samu
7/14/2008 3:43:03 AM

Hi

Thanks a lot for all your response. What I have learnt from this is we should not bind data to the drop down upon post back. If so then we can't get the  selected value. SO I changed my condition and bound the data ONLY when the page is loaded for the first time.

Thanks

Janakiraman 

 

 

-1
janakiraman
7/15/2008 1:06:36 PM
Reply:

Similar Artilces:

How to get value from dynamic control on Post-back
Hi All, This is my first post. The problem is about dynamic control. 1. In Page Load, I auto generated a datagrid.  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load         Dim lmws As New LIMSWSV10.LIMSService         Dim ds As New DataSet         If Not IsPostBack Then             ds = lmws.GetResultValueForShippingJob(Request.QueryString("ShippingJobID")) ...

Getting control value inside the grid at the post back
Hi,       I used the DropdownList control inside the gridview and i want to retrive the value of dropdown in gridview at the page postback. Is it possible to get the value using "Request.Form"? or is any other method to reteive the value?. Looking for help   Thanks  Dropdownlist ddl = (Dropdownlist)gridview1.rows[gridviewrowno].FindControl("dropdownlistid");string selvalue  = ddl.SelectedValue; in above you have to change  gridviewrowno to the rowno you wants to retrieve.dropdownlistid to the id of the dropdownlist in...

How to get table control values on post back event?
Hi, I am using table control in asp.net, there are 3 columns in the table, values of first two columns are added manually at design time and third column has text box where user needs to add values. On button click event i need to save table (cell) values of column2,column3, but some how on post back event values are disappearing in the table. There is no limit on rows, it can be one or 20 depends on user selection. Is there any way to save table values on post back event or can i disable post back event for button so that table values will not be disappeared? Thanks ...

Trouble getting selected value from DropDownList when posted back
I have a DropDownList inside a Repeater with AutoPostBack=True. I need to get the selectedvalue of the DropDownList so that I can populate another DropDownList based on its value. I was trying to do this in the Page_Load method but the value is coming back as null. Here's what I was trying. What am I doing wrong? Thanks <asp:DropDownList ID="OfficeDDL" runat="server" AutoPostBack="true" /><br />  if (Page.IsPostBack) { DropDownList OfficeDDL = (DropDownList)EmployeeOfficeAddressRepeater.FindControl...

Value of Control created dynamically is not getting populated on post back
Hi I am creating a table at run time. If I put some value to textbox, its not getting populated after post back. If I do it on Page onInit event everything works fine.. but I cant do this as I have to make rows on button click. The code is like this Sub MakeTable() Dim ht As New Hashtable ht("1") = "1" ht("2") = "2" For i As Integer = 0 To 2 Dim tr As New TableRow For j As Integer = 0 To 1 Dim td As New TableCell Select Case (j) ...

Composite Control
I've just got put back onto my old project and I spent a few hours getting back to grips with it.  The main part of it is a Composite Control I've built.This composite control builds itself from an XML file. It might contain 10 drop downs, 5 textboxes, or even 100 radio button lists.I have a strange issue when the parent page is refreshed via. a PostBack.  ----I set a drop down's value to the 9th item in the list. I click a button on the page to refresh it via a PostBack. When I go through the :         public override void RenderControl(System.We...

getting focus back to the same control after post back
Hi friends!  How the control can be set focused on the same conrol after post back from where it was generated?thanks At the event of the control which causes Postback , add {        ControlID.Focus() } in this wayprotected void Page_Load(object sender, EventArgs e) {if (IsPostBack) {Control control = null; string ctrlname = Page.Request.Params["__EVENTTARGET"];if (ctrlname != null && ctrlname != String.Empty) { control = Page.FindControl(ctrlname); control.Focus(); } }   }   Note this will work for all...

Web user control [retain values on post back with/out using static approach]
Hi, I'm developing application in 1.1. I've created one web user control which contains static properties & some private methods. This control is placed on y.aspx page. I'm opening y.aspx page from x.aspx page and passing querystring  to y to set static properties. Am I following right way? May be you guessed problem.  As I'm using static properties/variables, if another user try to access same page; values get overwritten. If I create instance it won't retain values on post back. How can I change my approach so that it will retain values as well...

How to maintain form controls value after user control post back?
 hello experts, I have created filter grid in asp.net & C#.My form design has contains 3 dropdown controls and Filter grid(User control).Its working fine(filter), but one problem arise.the form controls are clear when i filter a grid(post back).I tried to reterive values using view state, hidden controls, i got only null values.Anyone please help, its urgent to me. Its my user control code.FilterGrid.aspx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FilterGrid.ascx.cs" Inherits="FilterGrid" %><style type = "text/css&...

Drop down list control values OK but not showing selected value on UI
 Hi, I am having trouble with the following: ddlIndustry.Items.FindByText(oReader["industry"].ToString()).Selected = true;  I am trying to get the ddlIndustry drop down list to bind to a specific product industry got from a database like say "Agriculture". Even when i assign a hardwired and existent value like "Agriculture" as from the database,  the Selected value or text does change from initial option from the list with (this I verified in Debug mode) but when the page is generated, the Drop down list maintains value 0 and text "--select one --". Is there something i am...

getting selected data in grid view according to the selected value in drop down
hi! how can i change the grid view data according to the selected value in the drop down list? Make the DataSource the GridView is bound too have a select statement that uses the value of the dropdownlist as a parameter. hth, mcm  Bind your grid in your drop down selectedindexchange and reference the value being selected in your query likeprotected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){        string val = DropDownList1.SelectedItem.Text;        //Code for populating your grid here like ...

Drop Down List Populated Depending Upon the value Selected in another Drop Down List
  I have five drop down lists.Each One populated based on the value selected in the previious one. I have used SqlDataSource for binding data to each drop down.And I need some initial value so I put "AppendDataBoundItems" as true.Functionality is ok. The problem is, I have selected one from first dropdown.then second drop down is populated.but now i want to select a different value from first dropdown.If i do so,To my second drop down list the values r being appended.not refreshed.I think this is because AppendDataBoundItems=true Plz suggest me something. Thanks in Advan...

Drop Drop filled with AJAX Web Service Getting empty on Post Back.
Hi I am filling a Drop Down Control using AJAX WebService but i am facing a issue.  Issue: Drop Down is getting filed propery with the AJAX WebService and JavaScript Code. But now when the page is getting loaded after a postback, the contents of the drop down are getting lost. For Eg: I have a Drop Down and a button. The Drop Down is filled with AJAX WebService Code and on Button Click the page is doing postback and again  page is displayed. Now when the page loads back, the drop down which was filled with Ajax is empty.  I tried few things but was not able to identify wh...

Populate a second drop down list upon selection value of the first drop down list in a gridview
How to Populate a second drop down list upon selection value of the first drop down list in a gridview? DropDownList1 ******************* <asp:TemplateField HeaderText="SystemName" SortExpression="SystemName">                <EditItemTemplate>                    <asp:DropDownList ID="sysidddl" runat="server" DataSourceID="sysods1"    &nbs...

Web resources about - How to retain and get the selected value of the drop down upon post back - asp.net.presentation-controls

Portal:Law/Nominate/Selected article - Wikipedia, the free encyclopedia
Add the article in to a subpage of this portal, such as Portal:Law/Selected article/# , replacing the "#" with the number above the current highest. ...

F8: Facebook’s FbStart Initiative Will Give Selected Developers A $30K Kick-Start
... successful applications is likely a whole lot easier with $30,000 in free tools and services to start off with, and that’s exactly what selected ...

LEGO Shop - The LEGO Technic team has selected the winner... - Facebook
The LEGO Technic team has selected the winner of the Co-Creation Challenge! LEGO will be producing a limited run of 20,000 of this stunning set.... ...

baby365- Grand Doctor Ma Selected Students for iPad on the iTunes App Store
Get baby365- Grand Doctor Ma Selected Students on the App Store. See screenshots and ratings, and read customer reviews.

Selected Cheney Vice Presidential Photographs
... for photos found within these albums are Paul Morse, Karen Ballard, Kimberlee Hewitt, Shealah Craighead, and Chris Greenberg. These selected ...

[iOS Advice] How To Clarify Your Email Replies By Quoting Selected Text - YouTube
Follow me on Twitter: http://www.twitter.com/macmixing Like my Facebook page: http://www.facebook.com/macmixing RATE, COMMENT, SUBSCRIBE! :-) ...

Sait Faik Abasıyanık’s Selected Stories are tales that beguile all for their brevity
The influential Turkish writer's collection of short stories is often bizzare but never boring.

Animal of the Day: Lucius Has Been Selected as the U.K.’s ‘Happiest Cat’
He’s got one blue eye, one green eye and a heart of gold. British mobile phone company O2 recently held some “cat auditions” to find “the UK’s ...

Michael Sam becomes first openly gay player selected in an NFL Draft
Defensive end Michael Sam of the University of Missouri became the first openly gay player to be selected in a National Football League Draft ...

Refugee spinner selected for PM's XI
Fawad Ahmed has gone from asylum seeker to rubbing shoulders with Julia Gillard at The Lodge.

Resources last updated: 12/17/2015 6:47:09 PM