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. General Programming
  3. C#
  4. datalist with an embedded dropdownlist.

datalist with an embedded dropdownlist.

Scheduled Pinned Locked Moved C#
questiondatabasehardware
6 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.
  • C Offline
    C Offline
    Crapaw45
    wrote on last edited by
    #1

    I have a datalist with an embedded dropdownlist. How can I fire an event from the dropdownlist and caclulate the results for a label in the datalist? The datalist is similar to a shopping cart. The fore mentioned dropdownlist is the qty for each item. The total price is calculted using the qty and another field "PriceEach". Most of the data is retrieved from a sql stored produre. I wrote the following Item_Bound function to set the totalprice at the page_load. protected void Item_Bound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DropDownList ddlist = (DropDownList)e.Item.FindControl("ddlQty"); Label TotPrice = (Label)e.Item.FindControl("lblTotalPrice"); Label PriceEA = (Label)e.Item.FindControl("lblPrice"); if (PriceEA.Text != null && PriceEA.Text.ToString() != "") { string price = PriceEA.Text.Replace("$", ""); Double dblPrice = Convert.ToDouble(price); Double ProdQty = Convert.ToDouble(ddlist.SelectedValue.ToString()); Double ExtPrice = (dblPrice * ProdQty); TotPrice.Text = ExtPrice.ToString(); } } } :~

    A 1 Reply Last reply
    0
    • C Crapaw45

      I have a datalist with an embedded dropdownlist. How can I fire an event from the dropdownlist and caclulate the results for a label in the datalist? The datalist is similar to a shopping cart. The fore mentioned dropdownlist is the qty for each item. The total price is calculted using the qty and another field "PriceEach". Most of the data is retrieved from a sql stored produre. I wrote the following Item_Bound function to set the totalprice at the page_load. protected void Item_Bound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DropDownList ddlist = (DropDownList)e.Item.FindControl("ddlQty"); Label TotPrice = (Label)e.Item.FindControl("lblTotalPrice"); Label PriceEA = (Label)e.Item.FindControl("lblPrice"); if (PriceEA.Text != null && PriceEA.Text.ToString() != "") { string price = PriceEA.Text.Replace("$", ""); Double dblPrice = Convert.ToDouble(price); Double ProdQty = Convert.ToDouble(ddlist.SelectedValue.ToString()); Double ExtPrice = (dblPrice * ProdQty); TotPrice.Text = ExtPrice.ToString(); } } } :~

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Then what is the error you are getting... The code looks fine to me.

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Simplify Code Using NDepend
      Basics of Bing Search API using .NET
      Microsoft Bing MAP using Javascript

      C 1 Reply Last reply
      0
      • A Abhishek Sur

        Then what is the error you are getting... The code looks fine to me.

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Simplify Code Using NDepend
        Basics of Bing Search API using .NET
        Microsoft Bing MAP using Javascript

        C Offline
        C Offline
        Crapaw45
        wrote on last edited by
        #3

        I'm trying to add code to get the qty when it is changed. I added an event to the Dropdownlist "ddlQty" called OnSelectedIndexChanged="ddlQty_Changed" and started to add the following: protected void ddlQty_Changed(object sender, DataListItemEventArgs e) { DropDownList ddQty = (DropDownList)e.Item.FindControl("ddlQty"); if (ddQty.SelectedValue != null && ddQty.SelectedValue.ToString() != "") { Double ProdQty = Convert.ToDouble(ddQty.SelectedValue.ToString()); } } When I run this I get the error: No overload for 'ddlQty_Changed' matches delegate 'System.EventHandler'

        A 1 Reply Last reply
        0
        • C Crapaw45

          I'm trying to add code to get the qty when it is changed. I added an event to the Dropdownlist "ddlQty" called OnSelectedIndexChanged="ddlQty_Changed" and started to add the following: protected void ddlQty_Changed(object sender, DataListItemEventArgs e) { DropDownList ddQty = (DropDownList)e.Item.FindControl("ddlQty"); if (ddQty.SelectedValue != null && ddQty.SelectedValue.ToString() != "") { Double ProdQty = Convert.ToDouble(ddQty.SelectedValue.ToString()); } } When I run this I get the error: No overload for 'ddlQty_Changed' matches delegate 'System.EventHandler'

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          I think the signature of ddlQty_Changed should be protected void ddlQty_Changed(object sender, EventArgs e) :)

          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


          My Latest Articles-->** Simplify Code Using NDepend
          Basics of Bing Search API using .NET
          Microsoft Bing MAP using Javascript

          C 1 Reply Last reply
          0
          • A Abhishek Sur

            I think the signature of ddlQty_Changed should be protected void ddlQty_Changed(object sender, EventArgs e) :)

            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


            My Latest Articles-->** Simplify Code Using NDepend
            Basics of Bing Search API using .NET
            Microsoft Bing MAP using Javascript

            C Offline
            C Offline
            Crapaw45
            wrote on last edited by
            #5

            When I try that I can't find the "e.item" in: DropDownList ddQty = (DropDownList)e.Item.FindControl("ddlQty"); Fixed it: protected void ddlQty_Changed(object sender, EventArgs e) { foreach (DataListItem item in DataList1.Items) { Label TotPrice = (Label)item.FindControl("lblTotalPrice"); Label PriceEA = (Label)item.FindControl("lblPrice"); DropDownList ddlist = (DropDownList)item.FindControl("ddlQty"); if (ddlist.SelectedValue != null && ddlist.SelectedValue.ToString() != "") { string price = PriceEA.Text.Replace("$", ""); Double dblPrice = Convert.ToDouble(price); Double ProdQty = Convert.ToDouble(ddlist.SelectedValue.ToString()); Double ExtPrice = (dblPrice * ProdQty); TotPrice.Text = String.Format("${0:0,0}", ExtPrice.ToString()); } } } Thanks for all the help

            modified on Tuesday, November 10, 2009 3:55 PM

            A 1 Reply Last reply
            0
            • C Crapaw45

              When I try that I can't find the "e.item" in: DropDownList ddQty = (DropDownList)e.Item.FindControl("ddlQty"); Fixed it: protected void ddlQty_Changed(object sender, EventArgs e) { foreach (DataListItem item in DataList1.Items) { Label TotPrice = (Label)item.FindControl("lblTotalPrice"); Label PriceEA = (Label)item.FindControl("lblPrice"); DropDownList ddlist = (DropDownList)item.FindControl("ddlQty"); if (ddlist.SelectedValue != null && ddlist.SelectedValue.ToString() != "") { string price = PriceEA.Text.Replace("$", ""); Double dblPrice = Convert.ToDouble(price); Double ProdQty = Convert.ToDouble(ddlist.SelectedValue.ToString()); Double ExtPrice = (dblPrice * ProdQty); TotPrice.Text = String.Format("${0:0,0}", ExtPrice.ToString()); } } } Thanks for all the help

              modified on Tuesday, November 10, 2009 3:55 PM

              A Offline
              A Offline
              Abhishek Sur
              wrote on last edited by
              #6

              Thats nice. ;)

              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


              My Latest Articles-->** Simplify Code Using NDepend
              Basics of Bing Search API using .NET
              Microsoft Bing MAP using Javascript

              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