| | |
DropDownList only returns the 1st value regardless of selection
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2008
Posts: 34
Reputation:
Solved Threads: 0
Ive successfully managed to bind my DropDownList control to the membership.getAllUsers class. The problem is, no matter who i select from the list, it always returns the same value which is the first selection. Is this some kind of postback issue? Yikes!
ASP.NET Syntax (Toggle Plain Text)
Protected Sub fillDropList(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load DropList1.DataSource = Membership.GetAllUsers() DropList1.DataBind() End Sub Protected Sub DropList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropList1.SelectedIndexChanged results.Text = DropList1.SelectedItem.ToString() End Sub
•
•
Join Date: Jun 2009
Posts: 433
Reputation:
Solved Threads: 82
1
#2 31 Days Ago
Your dropdownlist bound to datasource for every submit. It should not be.
You need to check IsPostBack property on load event before binding the DropDownList.
Change your code as below
You need to check IsPostBack property on load event before binding the DropDownList.
Change your code as below
ASP.NET Syntax (Toggle Plain Text)
Protected Sub fillDropList(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then DropList1.DataSource = Membership.GetAllUsers() DropList1.DataBind() End If End Sub
Last edited by Ramesh S; 31 Days Ago at 2:13 am.
•
•
Join Date: Dec 2007
Posts: 205
Reputation:
Solved Threads: 11
0
#3 31 Days Ago
Have you specified
ASP.NET Syntax (Toggle Plain Text)
DropDownList1.DataTextField = ""; DropDownList1.DataValueField="";
•
•
Join Date: May 2008
Posts: 34
Reputation:
Solved Threads: 0
Ive tested the values for both gridView1 and dropList1 and they are exactly what I want them to be. Too bad I cant figure why the above error keeps popping up. Im no .net expert so im hoping this is just some kind of syntax or inconsistent dataType. Please help
ASP.NET Syntax (Toggle Plain Text)
Imports System.Security Imports System.Data.SqlClient Imports System.Web.Configuration Imports System.Data Partial Class admin Inherits System.Web.UI.Page Public connectPath As String = ConfigurationSettings.AppSettings("Maya") Protected Sub fillDropList(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then DropList1.DataSource = Membership.GetAllUsers() DropList1.DataBind() End If End Sub Protected Sub DropList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropList1.SelectedIndexChanged Dim theUser2 As Integer = gridView1.SelectedDataKey.Value Dim con As New SqlConnection con.ConnectionString = connectPath 'the customerID of the selected gridview row Dim setRep As New SqlCommand setRep.Connection = con setRep.CommandText = "INSERT INTO dbo.customers(rep)VALUES(@dropList1)WHERE rep='" & theUser2.ToString() & "'" setRep.Parameters.AddWithValue("@dropList1", DropList1.SelectedItem.ToString()) Dim added As Integer = 0 Try con.Open() added = setRep.ExecuteNonQuery() results.Text = added.ToString() & "record has been added!" Catch Err As Exception results.Text = "Error inserting record. " results.Text &= Err.Message Finally con.Close() End Try End Sub End Class
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 1
0
#6 31 Days Ago
Bind the Dropdown when not ispostback . Otherwise Dropdown rebinds on every postback
Parmesh
videozcorner
videozcorner
![]() |
Similar Threads
- queue (C++)
- Problem Related Dropdownlist in Data Grid (ASP.NET)
- pass array by reference (C)
- Help with Creating Unique Numbers for a Lottery Simulation (Java)
- populating dropdownlist based on gridview selection (ASP.NET)
- ASCII (Visual Basic 4 / 5 / 6)
- Dynamic rows & controls in a table - problem (ASP)
- Need help with a homework assignment. (Java)
- problem with OPERA and SAFARI...help please (IT Professionals' Lounge)
- Help on a recursive function (C++)
Other Threads in the ASP.NET Forum
- Previous Thread: Opera most used version (besides latest)
- Next Thread: how to get the header name for the datatable in C#
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox class click commonfunctions compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock deployment development dgv dropdownlist dropdownmenu dynamic edit embeddingactivexcontrol expose findcontrol flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery list login menu microsoft mono mssql multistepregistration nameisnotdeclared numerical objects order panelmasterpagebuttoncontrols problem ratings rotatepage save schoolproject search security serializesmo.table silverlight smartcard sql sqlserver2005 ssl suse textbox tracking unauthorized validation vb.net video virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webdevelopment webservice wizard xml youareanotmemberofthedebuggerusers





