datalist with an embedded dropdownlist.
-
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(); } } } :~
-
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(); } } } :~
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 -
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 JavascriptI'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'
-
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'
I think the signature of
ddlQty_Changed
should beprotected 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 -
I think the signature of
ddlQty_Changed
should beprotected 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 JavascriptWhen 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
-
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
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