cascading dropdown set it's value only once but not on subsequent postbacks,web service recieve the value but can't set in dropdown


i have a dropdown named uxcommunity which is a dropdown and contain text in format ##-####-#### . and 2 more dropdowns province and district where province filters district.

i get the first 2 characters ##  for session("province") and #### for session("District") and i have button to do the postback.

first when the form loads and i click the button it get the value and select appropraite items in to dropdown province and district.

but when i change the province dropdown content and district dropdown content and click the button ,

session will take correct value event the web service takes the value but it doesn't set the value in 2 dropdowns.

Session(
"ProvinceID") =  Mid(uxCommunity.SelectedItem.Text, 1, 2)

Session("districtId") =  Mid(uxCommunity.SelectedItem.Text, 4, 4)

 <WebMethod(EnableSession:=True)> _ Public Function GetProvince(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()

Try

Dim dt As New DataTable

Using connection = New SqlConnection(ConfigurationManager.ConnectionStrings("NSPConnectionString").ToString)

Dim Cmd As SqlCommand = New SqlCommand("SELECT Province, ProvinceID2 from look.PROVINCES order by province", connection)Dim Adp As SqlDataAdapter = New SqlDataAdapter(Cmd)

Adp.Fill(dt)

Adp.Dispose()

End Using

Dim v(dt.Rows.Count - 1) As CascadingDropDownNameValue

For i As Integer = 0 To dt.Rows.Count - 1

v(i) = New CascadingDropDownNameValue

v(i).name = dt.Rows(i)("Province")

v(i).value = dt.Rows(i)("ProvinceID2")

If Session("ProvinceID") IsNot Nothing AndAlso v(i).value = Session("ProvinceID") Then

v(i).isDefaultValue = True

End If

Next

Return v Catch ex As Exception

'Log(ex.ToString)

End Try

Return Nothing

End Function

<WebMethod(EnableSession:=True)> _

Public Function GetDistricts(ByVal knownCategoryValues As String, ByVal category As String) _

As CascadingDropDownNameValue()

Try

Dim kv As StringDictionary = _

CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

Dim ProvinceID As Integer = -1

Dim values As New List(Of CascadingDropDownNameValue)

If Not (kv.ContainsKey("Province") AndAlso Int32.TryParse(kv("Province"), ProvinceID)) Then _

Return values.ToArray

Dim dt As New DataTable

Using connection = New SqlConnection(ConfigurationManager.ConnectionStrings("NSPConnectionString").ToString)

Dim Cmd As SqlCommand = New SqlCommand("select '<-All->' as district ," & ProvinceID & " as districtid2,0 as FacilitatingPartnerID union select district, districtId2,FacilitatingPartnerID from look.DISTRICTS where ProvinceID=" & ProvinceID & " order by district ", connection)Dim Adp As SqlDataAdapter = New SqlDataAdapter(Cmd)

Adp.Fill(dt)

Adp.Dispose()

End Using

Dim v(dt.Rows.Count - 1) As CascadingDropDownNameValue

For i As Integer = 0 To dt.Rows.Count - 1

v(i) = New CascadingDropDownNameValue

v(i).name = dt.Rows(i)("district")

v(i).value = dt.Rows(i)("districtId2")

If Session("districtId") IsNot Nothing AndAlso v(i).value = Session("districtId").ToString Then

v(i).isDefaultValue = True

End If

Next

Return v Catch ex As Exception

'Log(ex.ToString)

End Try

Return Nothing

End Function

0
sultani
10/21/2008 5:15:58 AM
asp.net.ajax_control_toolkit 17816 articles. 1 followers. Follow

1 Replies
1052 Views

Similar Articles

[PageSpeed] 10

Here is the salution finally i go it through my friend support, hope it will help some one else searching for the similar problem.

Session("ProvinceID") = Mid(uxCommunity.SelectedItem.Text, 1, 2)

CDDProvince.SelectedValue = Session("ProvinceID")

Session("districtId") = Mid(uxCommunity.SelectedItem.Text, 4, 4)

CDDDistrict.DataBind()

CDDDistrict.SelectedValue = Session("districtId")

web service

<WebMethod(EnableSession:=True)> _ Public Function GetProvince(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()

Try

Dim dt As New DataTable

Using connection = New SqlConnection(ConfigurationManager.ConnectionStrings("NSPConnectionString").ToString)

Dim Cmd As SqlCommand = New SqlCommand("SELECT Province, ProvinceID2 from look.PROVINCES order by province", connection)Dim Adp As SqlDataAdapter = New SqlDataAdapter(Cmd)

Adp.Fill(dt)

Adp.Dispose()

End Using

Dim v(dt.Rows.Count - 1) As CascadingDropDownNameValue

For i As Integer = 0 To dt.Rows.Count - 1

v(i) = New CascadingDropDownNameValue

v(i).name = dt.Rows(i)("Province")

v(i).value = dt.Rows(i)("ProvinceID2")

NextReturn v Catch ex As Exception

'Log(ex.ToString)

End Try

Return Nothing

End Function

<WebMethod(EnableSession:=True)> _

Public Function GetDistricts(ByVal knownCategoryValues As String, ByVal category As String) _

As CascadingDropDownNameValue()

TryDim kv As StringDictionary = _

CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

Dim ProvinceID As Integer = -1

Dim values As New List(Of CascadingDropDownNameValue)

If Not (kv.ContainsKey("Province") AndAlso Int32.TryParse(kv("Province"), ProvinceID)) Then _

Return values.ToArray

Dim dt As New DataTable

Using connection = New SqlConnection(ConfigurationManager.ConnectionStrings("NSPConnectionString").ToString)Dim Cmd As SqlCommand = New SqlCommand("select '<-All->' as district ," & ProvinceID & " as districtid2,0 as FacilitatingPartnerID union select district, districtId2,FacilitatingPartnerID from look.DISTRICTS where ProvinceID=" & ProvinceID & " order by district ", connection)Dim Adp As SqlDataAdapter = New SqlDataAdapter(Cmd)

Adp.Fill(dt)

Adp.Dispose()

End Using

Dim v(dt.Rows.Count - 1) As CascadingDropDownNameValue

For i As Integer = 0 To dt.Rows.Count - 1

v(i) = New CascadingDropDownNameValue

v(i).name = dt.Rows(i)("district")

v(i).value = dt.Rows(i)("districtId2")

NextReturn v Catch ex As Exception

'Log(ex.ToString)

End Try

Return Nothing

End Function

0
sultani
10/23/2008 11:17:40 AM
Reply:

Similar Artilces:

Can't set value in dropdown list
I have a dropdown list box that I need to set the value at runtime. I am doing this in the Page Load event. First I load the values into the ddl and then I try to select a value based on a value passed in a querystring. If Request.QueryString("filenum") <> "" Then itm = Me.ddlState.Items.FindByValue(CType(Request.QueryString("filenum"), Integer)) nIndex = Me.ddlState.Items.IndexOf(itm) Me.ddlState.SelectedIndex = nIndex End If I have tried without the CType but I get the same result. itm = nothing Thanks, enak Well, assuming that Request.QueryString("filenum") equates to a ...

superreview requested: [Bug 407538] newURI("http://foo.com:80").port is 80, should be -1 (can set a URI's port to it's default value by setting .spec) : [Attachment 292260] patch
Gavin Sharp <gavin.sharp@gmail.com> has asked Christian :Biesinger <cbiesinger@gmx.at> for superreview: Bug 407538: newURI("http://foo.com:80").port is 80, should be -1 (can set a URI's port to it's default value by setting .spec) https://bugzilla.mozilla.org/show_bug.cgi?id=407538 Attachment 292260: patch https://bugzilla.mozilla.org/attachment.cgi?id=292260&action=edit ------- Additional Comments from Gavin Sharp <gavin.sharp@gmail.com> I'm not sure about the XXX comment in the test - seems like we should probably fix that, too, but I&...

Can't Set A Variable (Referenced object has a value of 'Nothing'.)
 Hey Everyone, I'm trying to populate an object with values from a database, but, I cannot seem to change it. When I set a breakpoint and use the immediate window (and attempt to set values manually), I get "Referenced object has a value of 'Nothing'.". Additionally, I've confirmed that the IDataReader is working... Here's the code in question:   Public Function GetAnnouncement(ByVal AnnouncementID As Integer) As Announcement Implements IAnnouncementDB.GetAnnouncement Dim rAnnouncement As Announcement Dim cmd As N...

Can a User Control's Page_Load retrieve a value set in the parent's Page_Load?
I want to use a control to perform a specific task, but I want it to vary based on the page it is on. I was hoping to set a value in the Page_Load event of the Parent, and have that value retrieved by the Page_Load event of the user control. I am not sure what order these events fire in, Can I be certain that the parent event will fire first?...

Populating a Dropdown after a postback based on another Dropdown's value
In my application, when the user clicks 'Add Row', a row of controls that are created in the code behind. When I click on the dropdownlist for Offices, the page postback and retrieves the value of the Office that was selected. I then want to use this value to populate another dropdownlist with the correct floors for that office. I can get the value of the Office, but I'm having trouble using it. Here is what I have:  public partial class EmployeeOfficeAddress : System.Web.UI.Page { int rows = 0; Label vldOffice = new Label(); Label vldFloor =...

setting dropdown value isn't working
I'm trying to pass values from one page to the next by sending values in the link so that when it paints a page, three dropdowns will be set.  Two of the three are values that I set, the other is coming from a database. protected void Page_Load(object sender, EventArgs e) { string fac = Request.QueryString["fac"]; string year = Request.QueryString["year"]; string qtr = Request.QueryString["qtr"]; try { if (year != null) { ddlYear.Items.FindByValue(year).S...

It's all very fuzzy now...can make web request(?) but definately can't get web response from web service
Alas...trying to get a web service response from a web service that is part of the web site in Visual Studio.Net 3.5 appears to be impossible.  Infact, I've been ALL over the internet over the past couple of days looking at all types of fragmentory examples in all types of Microsoft languages to no avail. =========QUESTION:=========1.  How do I call a web service (the function to call is "WebService_BulkData") so that my aspx page will send it a SOAP request and print out the web service response data to the page?  The aspx page AND the web service are part of t...

setting dropdown.selectedvalue
I need to set a dropdown.selectedvalue via a parameter passed in the url.  It works fine if the value passed is a valid value.  However, if the value passed is not a valid value for the dropdown, it logically returns the error: cbcase.has a SelectedValue which is invalid because it does not exist in the list of items. What is the best way to catch this error and handle it gracefully??  That is, how can I test to see if whats passed is a valid value and if not, gracefully recover? heres  my .aspx code, I'm dealing with cbCase <asp:Literal ID="Lite...

Cookie set in radWindow doesn't keep it's values in parent
Hi,  I have an asp.net page that calls a radWindow. In this window I set a cookie with 2 values. When I close the window and check the cookies in the opener window, I only see the cookies' name, but no values. Anyone has an idea on the cause? Thanks?  Function that sets the cookie. Private Const JAVASCRIPTSOUMETTRECLICK As String = vbCrLf & "function btnOk_Click()" & vbCrLf & _ "{" & vbCrLf & _ " var oWindow = GetRadWindow();" & vbCrLf & _ " var numeroDuGroupeValeur = ""&q...

set field in row to selected value from row's dropdown
Man, I'm just getting deeper and deeper into this dataset <> gridview thing ... I have a gridview of Questions. Each row has a dropdown whose selected is set to the question's current Category. By reselecting from the Category drop down, I can reassign the question to another Category. So, in pseudocode: ddlThisQuestionsCategory_SelectedIndexChanged(){    dsQues.thisRow.Item["category"] = ddlThisQuestionsCategory.selected.Value    dsQues.AcceptChanges();    updateQuestions(dsQues);} I don't know how to do this. Her...

Need multi-valued dropdown list but can't use standard value + text solution
I have a situation where I am filling a dropdown list from a datasource that is created from a Web services call (specifically, city-state pairs based on a zipcode lookup). The text field is 'city' however I can't use the value field for 'state' because in virtually all cases the state will be the same--although I can't count on this always being the case. (Having the same value for multiple entries in the list gets the dropdown list really upset, apparently!) So, what is another option as it does not appear that we can add keys to lists (which would solve the problem, of course)? Thanks! D...

Setting my DropDown item programmatically doesn't update the underlying value
I have a DropDownList that has a "face" value (Description) and underlying Code. This has worked fine so far, but now I added code to automatically set the right item selected based on another entry, and the underlying value is no longer moving along with the "face" value (it is now stored in the database as "0"). Here is my code:      protected void TextBox_UnitSerialNumber_TextChanged( object sender, EventArgs e )    {      string sCandidateSerialNum = TextBox_UnitSerialNumber.Text;  &...

Unable to set '0' value to 'identity_burn_max'
Hi , Server Details : Solaris Sparc Database : ASE 12.5.3 (with no ESDs) We are having a table and one of the column in the table is an 'numeric (10,0) identity' column. I am trying to reset the identity sequence to 1 using dbcc set_identity_burn_max(dms_uat,updateWorkBalagopalanS14470,'1') This is working fine. But if I try to reset the identity column value to '0' dbcc set_identity_burn_max(dms_uat,updateWorkBalagopalanS14470,'0') I am getting the following error. 'Error: Number (15014) Severity (16) State (2) Server (I...

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to asp.net i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.http://www.heliosfx.com...