| | |
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: 439
Reputation:
Solved Threads: 82
1
#2 Oct 28th, 2009
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; Oct 28th, 2009 at 2:13 am.
•
•
Join Date: Dec 2007
Posts: 205
Reputation:
Solved Threads: 11
0
#3 Oct 28th, 2009
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 Oct 28th, 2009
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 ajax alltypeofvideos appliances application asp asp.net bc30451 beginner box browser button c# cac checkbox class commonfunctions control countryselector dataaccesslayer database datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose feedback fileuploader fill findcontrol flash form formatdecimal formview gridview gudi iis javascript listbox login microsoft mouse mssql news novell numerical opera panelmasterpagebuttoncontrols parent problem radio redirect registration relationaldatabases reportemail save schoolproject search security select sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





