Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Parse the selected value from ddl and fill another ddl with information + NHibernate + C#

Parse the selected value from ddl and fill another ddl with information + NHibernate + C#

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-netquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thommie h
    wrote on last edited by
    #1

    Hi, I hope someone can help with with my problem, i have searched the Internet for information but i couldnt find any examples neither the answear. I use NHibernate and c# for my asp.net site. I have the "classic" problem. I have a dropdownlist with "Regions" and another one "Municipalities". When I choose an item in the ddlRegions the appropiate municipalites should be shown in ddlMunicipalties. I cant get this to work, do anyone have a code that does this and could share it with me? I have tried for a few evenings but i cant get it to work. Thanks Thommie

    M 1 Reply Last reply
    0
    • T Thommie h

      Hi, I hope someone can help with with my problem, i have searched the Internet for information but i couldnt find any examples neither the answear. I use NHibernate and c# for my asp.net site. I have the "classic" problem. I have a dropdownlist with "Regions" and another one "Municipalities". When I choose an item in the ddlRegions the appropiate municipalites should be shown in ddlMunicipalties. I cant get this to work, do anyone have a code that does this and could share it with me? I have tried for a few evenings but i cant get it to work. Thanks Thommie

      M Offline
      M Offline
      Marco van der Linden
      wrote on last edited by
      #2

      Hi Thommie, I think your looking for somting like this: private void ddlRegions_SelectedIndexChanged(object sender, System.EventArgs e) { RetrieveMunicipalities( int.Parse( ddlRegions.SelectedValue ) ); } private void RetrieveMunicipalities( int region) { ddlMunicipalities.DataSource = Retrieve_Municipalities( region); ddlMunicipalities.DataBind(); } Greetins, Marco van der Linden

      T 1 Reply Last reply
      0
      • M Marco van der Linden

        Hi Thommie, I think your looking for somting like this: private void ddlRegions_SelectedIndexChanged(object sender, System.EventArgs e) { RetrieveMunicipalities( int.Parse( ddlRegions.SelectedValue ) ); } private void RetrieveMunicipalities( int region) { ddlMunicipalities.DataSource = Retrieve_Municipalities( region); ddlMunicipalities.DataBind(); } Greetins, Marco van der Linden

        T Offline
        T Offline
        Thommie h
        wrote on last edited by
        #3

        Hi Marco, Whats "= Retrieve_Municipalities( region)"? is that a method to bind the data from the database? can you please show me? Thanks for the answear Thommie

        M 1 Reply Last reply
        0
        • T Thommie h

          Hi Marco, Whats "= Retrieve_Municipalities( region)"? is that a method to bind the data from the database? can you please show me? Thanks for the answear Thommie

          M Offline
          M Offline
          Marco van der Linden
          wrote on last edited by
          #4

          Hi Thommie, Its a method that retrieve data from the database. public DataTable Retrieve_Municipalities( int region) { string connectieString = ConfigurationSettings.AppSettings["ConnectieString"]; SqlConnection connectie = new SqlConnection(connectieString); SqlCommand commando = new SqlCommand("spRetrieveMunicipalities", connectie); SqlDataAdapter adapter = new SqlDataAdapter(commando); commando.CommandType = CommandType.StoredProcedure; SqlParameter parameterHoofdgroep = new SqlParameter("@region", SqlDbType.Int); parameterregion.Value = region; commando.Parameters.Add(parameterregion); DataTable regions= new DataTable(); adapter.Fill(regions); connectie.Close(); return regions; } Greetings, Marco :doh:

          T 1 Reply Last reply
          0
          • M Marco van der Linden

            Hi Thommie, Its a method that retrieve data from the database. public DataTable Retrieve_Municipalities( int region) { string connectieString = ConfigurationSettings.AppSettings["ConnectieString"]; SqlConnection connectie = new SqlConnection(connectieString); SqlCommand commando = new SqlCommand("spRetrieveMunicipalities", connectie); SqlDataAdapter adapter = new SqlDataAdapter(commando); commando.CommandType = CommandType.StoredProcedure; SqlParameter parameterHoofdgroep = new SqlParameter("@region", SqlDbType.Int); parameterregion.Value = region; commando.Parameters.Add(parameterregion); DataTable regions= new DataTable(); adapter.Fill(regions); connectie.Close(); return regions; } Greetings, Marco :doh:

            T Offline
            T Offline
            Thommie h
            wrote on last edited by
            #5

            Hi, My code looks like this and it doesnt work: This is with NHibernate. The error code : fetchQ.ParamName = "Region.Id"; The error text: NHibernate.QueryException: Type mismatch in NHibernate.Expression.EqExpression: Region.Id expected type System.Int32, actual type System.String RegionId in database is int. And the hbm file is mapped Int32 private void BindMunicipalities(int regionId) { try { string municipalityHql = "SELECT count(municipality.Id) from Municipality municipality WHERE municipality.Region.Id = :regionId"; IList queries = new List(); Query q = new Query(); q.ParamInt = regionId; q.ParamName = "regionId"; queries.Add(q); int municipalityCount = DataManagement.CoreRepository.RunCountStatement(municipalityHql, queries); if (municipalityCount > 0) { IList fetchQueries = new List(); Query fetchQ = new Query(); fetchQ.ParamName = "region.Id"; fetchQ.ParamInt = regionId; fetchQ.ParamEvaluationType = EvaluationType.Equals; fetchQ.ParamString = string.Empty; fetchQueries.Add(fetchQ); IList municipalities = DataManagement.CoreRepository.GetAll(fetchQueries, 0, 0, true, "Name"); ddlMunicipality.DataValueField = "Id"; ddlMunicipality.DataTextField = "Name"; ddlMunicipality.DataSource = municipalities; ddlMunicipality.DataBind(); } } catch (Exception ex) { logger.Error("Failed to load municipalities.", ex); this.lblError.Visible = true; } } protected void ddlRegions_SelectedIndexChanged(object sender, EventArgs e) { this.BindMunicipalities(int.Parse(this.ddlRegions.SelectedValue)); }

            modified on Thursday, March 20, 2008 5:16 PM

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups