Click here to Skip to main content
15,883,957 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I populate a ddl(2) from sql based upon the selecteted index of another ddl(1).

The problem is that when i press the action button first value of ddl(2) is always what is selected no matter what I have manually selected.

<asp:DropDownList ID="ddlToSection" runat="server" CssClass="ddlLong" OnSelectedIndexChanged="ddlToSection_SelectedIndexChanged" AutoPostBack="false">


pls suggest
thanks
Posted
Comments
John C Rayan 27-Feb-15 11:10am    
what do you mean action button? can you explain with some more code.
atul sharma 5126 27-Feb-15 11:50am    
Dear John,
I use 2 ddl. ddlToProject and ddlsection.
ddltoProject is populated at page load. following is the code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then
Call subFromProject()
If dtProjects.Rows.Count > 0 Then
ddlToProject.DataValueField = "PROJC"
ddlToProject.DataTextField = "PROJECT"
ddlToProject.DataSource = dtProjects
ddlToProject.DataBind()
End If
End If

btnShift.Attributes.Add("onclick", "return confirm('Do you want to shift the machine?')")
End Sub

In selected index change event of ddlToProject, the 2nd ddl i.e. ddlsection is populated.


Protected Sub ddlToProject_SelectedIndexChanged(sender As Object, e As EventArgs)
If ddlToProject.SelectedValue <> "" Then
Call subSection()
End If
End Sub

Then I press a shift button for a update command in sql database.

Now, while debugging I found that the ddlsection value is always reaching as the first item in its list, no matter which section I have selected. Hope I am able to explain the issue clearly.

Thanks for support.
Peter Leow 27-Feb-15 11:14am    
I suspect it did not postback as the AutoPostBack="false".

1 solution

It seems that it did not postback as the AutoPostBack="false".
Walkthrough this tutorial Creating Cascading DropDownLists in ASP.Net[^]
 
Share this answer
 
Comments
atul sharma 5126 27-Feb-15 11:41am    
thanks for the reply!
I have initially started without the autopostback and tried to make false only for solving this issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900