Hello,
I am trying to create a vb.net 2005 web page using the Atlas cascadingdropdown control from the toolkit. Ideally I would like it to work like the sample demonstration at:
http://atlas.asp.net/atlastoolkit/CascadingDropDown/CascadingDropDown.aspx
But I can't seem toget it to work. Does someone have a working sample (vb or c#) of doing it the same way? By the same way I mean, when the page loads displaying multiple drop down lists with the first list populated and showing the watermark, and the rest of the dropdowns showing the watermark but disabled. When any item in the first drop down is selected, it should populate and enable the second drop down, etc.
When I code it, the first and second drop downs are disabled, enabled properly, but when I perform the callback from the first dropdown having changed, for some reason it is not recorded as changed within the code behind in tha application. What I have for my web page and code behind is (note that ddlCatalogItem is the first drop down, and ddlFrontImage is the second). Note that in the code behind in the procedure ddlCatalogItem_SelectedIndexChanged the value ddlCatalogItem.SelectedValue is not correct! Why?
<tr>
<tdstyle="width: 76px; text-align: right"class="formheading"valign="top">Catalog Item
</td><tdstyle="width: 278px"valign="top"><asp:DropDownListID="ddlCatalogItem"runat="server"CssClass="formheading"AutoPostBack="True"OnSelectedIndexChanged="ddlCatalogItem_SelectedIndexChanged"></asp:DropDownList></td></tr><tr><tdstyle="width: 76px; text-align: right"class="formheading"valign="top">Front Image
</td><tdstyle="width: 278px"valign="top"><atlas:UpdatePanelMode=ConditionalID="UpdatePanel1"runat="server"><ContentTemplate><asp:DropDownListID="ddlFrontImage"runat="server"CssClass="formheading"></asp:DropDownList></ContentTemplate><Triggers><atlas:ControlValueTriggerControlID="ddlCatalogItem"PropertyName="SelectedValue"/></Triggers></atlas:UpdatePanel></td></tr>And in the code behind for that page I have:
ProtectedSub ddlCatalogItem_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)BindImageList(ddlCatalogItem.SelectedValue)
EndSubPrivateSub BindImageList(ByVal CatalogItemIDAsInteger)Dim sqlConn1AsNew SqlConnection()Dim drAs SqlDataReadersqlConn1.ConnectionString =
"Data Source=PD-dev;Initial Catalog=Tapestry;Persist Security Info=True;User ID=sa;Password=s@dotnet.itags.org.w*"sqlConn1.Open()
Dim oSQLAsNew SqlCommand("spReadFrontImageByCatalogItem", sqlConn1)oSQL.CommandType = CommandType.StoredProcedure
' Add the parameters to the command objectoSQL.Parameters.Add(
"@dotnet.itags.org.CatalogItemID", SqlDbType.SmallInt, 0).Value = CatalogItemID' Run the stored procedureTryDim ImagesAsNew DataTable("Images")Images.Columns.Add(
"Description", System.Type.GetType("System.String"))Images.Columns.Add(
"ProductFamilyID", System.Type.GetType("System.String"))dr = oSQL.ExecuteReader
Images.Load(dr)
ddlFrontImage.DataSource = Images
ddlFrontImage.DataTextField =
"Description"ddlFrontImage.DataValueField =
"ProductFamilyID"ddlFrontImage.DataBind()
Catch exAs SqlExceptionMsgBox(ex.Message, MsgBoxStyle.Critical,
"Error")EndTrysqlConn1.Close()
EndSub
Thanks!
Jim
Hi jjr -
Looking at your code, I don't see the CascadingDropDown extender declared anywhere.
Take a look at the walk through on my blog and post again if you're still having troubles:
http://blogs.msdn.com/sburke/archive/2006/04/14/576421.aspx
Thanks,
Shawn
Hi Shawn,
When I take out my ddlCatalogSelectedIndexChanged function, and set up the extender, I only see a blank list from my webservice. The webservice functions are defined as shown below.. why won't those return anything to my drop down listboxes?
the web page extender definition
<atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlCatalogItem"Category="Item"PromptText="Select item to order"ServicePath="ListcountService.asmx"ServiceMethod="GetCatalogItems"/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlFrontImage"ParentControlID="ddlCatalogItem"PromptText="Select the front image"ServiceMethod="GetImages"ServicePath="ListcountService.asmx"Category="Image"/></atlasToolkit:CascadingDropDown>the webservice code
:
<WebMethod()> _
PublicFunction GetImages(ByVal knownCatelogItemsAsString,ByVal ItemAsString)As CascadingDropDownNameValue()Dim kvAs StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCatelogItems)Dim ItemIdAsIntegerIf (Not kv.ContainsKey("Item")OrNot Int32.TryParse(kv("Item"), ItemId))ThenThrowNew ArgumentException("Couldn't find Item.")EndIfDim sqlConn1AsNew SqlConnection()Dim drAs SqlDataReadersqlConn1.ConnectionString =
"Data Source=PD-dev;Initial Catalog=Tapestry;Persist Security Info=True;User ID=sa;Password=s@.w*"sqlConn1.Open()
Dim oSQLAsNew SqlCommand("spReadFrontImageByCatalogItem", sqlConn1)oSQL.CommandType = CommandType.StoredProcedure
' Add the parameters to the command objectoSQL.Parameters.Add(
"@.CatalogItemID", SqlDbType.SmallInt, 0).Value = ItemId' Run the stored procedureTrydr = oSQL.ExecuteReader
Catch exAs SqlExceptionEndTrysqlConn1.Close()
Dim valuesAsNew List(Of CascadingDropDownNameValue)()Dim drowAs DataRowForEach drowIn drvalues.Add(
New CascadingDropDownNameValue(drow("Description"), drow("ProductFamilyID").ToString()))NextReturn values.ToArray()EndFunction<WebMethod()> _
PublicFunction GetCatalogItems()As CascadingDropDownNameValue()Dim sqlConn1AsNew SqlConnection()Dim drAs SqlDataReadersqlConn1.ConnectionString =
"Data Source=PD-dev;Initial Catalog=Tapestry;Persist Security Info=True;User ID=sa;Password=s@.w*"sqlConn1.Open()
Dim oSQLAsNew SqlCommand("spGetAllCatalogItems", sqlConn1)oSQL.CommandType = CommandType.StoredProcedure
' Run the stored procedureTrydr = oSQL.ExecuteReader
Catch exAs SqlExceptionEndTrysqlConn1.Close()
Dim valuesAsNew List(Of CascadingDropDownNameValue)()Dim drowAs DataRowForEach drowIn drvalues.Add(
New CascadingDropDownNameValue(drow("Description"), drow("ID")))NextReturn values.ToArray()EndFunctionThanks!
Jim
My guess is because of this spelling typo. The way Atlas does it's webservice proxies, the names need to be exact.
Public Function GetImages(ByVal knownCatelogItemsAs String,ByVal ItemAs String)should bePublic Function GetImages(ByVal knownCategoryItemsAs String,ByVal categoryAs String)
Hi Jim,
I've played with the code you provided and tweaked it to work on my machine. I removed your data access code in the webservice and filled it with stubs. Here's the.aspx page:
<%@. Page Language="VB" %><%@. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Test Page</title></head><body><form runat="server"><div> <atlas:ScriptManager ID="ScriptManager1" runat="server" /> <table> <tr> <td align="right">Catalog Item</td> <td><asp:DropDownList ID="ddlCatalogItem" runat="server"></asp:DropDownList></td> </tr> <tr> <td align="right">Front Image</td> <td><asp:DropDownList ID="ddlFrontImage" runat="server"></asp:DropDownList></td> </tr> </table> <atlasToolkit:CascadingDropDown ID="cdd" runat="server"> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddlCatalogItem" Category="Item" ServicePath="ListcountService.asmx" ServiceMethod="GetCatalogItems" PromptText="Select item to order" /> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddlFrontImage" ParentControlID="ddlCatalogItem" Category="Image" ServicePath="ListcountService.asmx" ServiceMethod="GetImages" PromptText="Select the front image" /> </atlasToolkit:CascadingDropDown></div></form></body></html>
And here's the code for the web service:
Imports System.Web.ServicesImports AtlasControlToolkit<WebService(Namespace:="http://tempuri.org/")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _Public Class ListcountServiceInherits System.Web.Services.WebService <WebMethod()> _Public Function GetCatalogItems(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As CascadingDropDownNameValue()Return New CascadingDropDownNameValue() _ {New CascadingDropDownNameValue("Fruit", 0),New CascadingDropDownNameValue("Vegetable", 1)}End Function <WebMethod()> _Public Function GetImages(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As CascadingDropDownNameValue()Dim kvAs StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)Dim ItemIdAs Integer If (kv.ContainsKey("Item")And Int32.TryParse(kv("Item"), ItemId))Then If (ItemId = 0)Then Return New CascadingDropDownNameValue() _ {New CascadingDropDownNameValue("Apple", 2), _New CascadingDropDownNameValue("Pear", 3), _New CascadingDropDownNameValue("Banana", 4)}ElseIf (ItemId = 1)Then Return New CascadingDropDownNameValue() _ {New CascadingDropDownNameValue("Potato", 5), _New CascadingDropDownNameValue("Lettuce", 6), _New CascadingDropDownNameValue("Corn", 7)}End If End If Return New CascadingDropDownNameValue() {}End FunctionEnd Class
A couple of things to note:
- You need to implement the default constructor forCascadingDropDownNameValue as menionted in David's last post athttp://forums.asp.net/thread/1257783.aspx.
- Instead of throwing exceptions in your web services you should return an empty list if you have no data to fill. I believe it's the expectation made by theCascadingDropDownBehavior.
If this doesn't work or you have any other questions, just let us know.
Thanks,
Ted
I think I have most of it working now, but I am curious, how do I do the enabling / disabling of the second list box in the cascade? I would like the second listbox to be disabled on start of the web page, and then enabled only if the 'select' option is not chosen in the first listbox; and I cannot seem to figure out how to do that!
I do have the listboxes being filled properly and the first listbox successfully loads the second!
However, I do note that the webservice function to load the second list is called on page startup, at which time I have not yet selected anything, is there a way to buypass this extra call?
Thanks!
Jim
Hi Jim,
Are you throwing exceptions in your web service methods? I believe that throwing exceptions instead of returning an empty list causes behavior similar to what you're describing. If that's not the case though, feel free to post your code again and we can take a look.
Thanks,
Ted
Forget my last question, it all works now!
Now I am down to a very basic question, can I have it so when I change the selection in the first dropdownlist in the cascade, that it always resets the second dropdownlist in the cascaed to the first watermark item which is 'select...'?
How would I do that?
Thanks!
Jim
Hi Jim,
If I understand what you're asking, I think this should happen automatically. The working code I posted above does this on my machine. If you're experiencing different behavior, take a careful look to see if anything is different. If it all looks the same though, you can post your code and I'll take another look.
Thanks,
Ted
Ted,
In mine, if I select an item from the second dropdown, and then change the first dropdown, the second doesn't automatically change to select like I would expect... instead it stays on a different item... is that how it is supposed to work?
Jim
Hi Jim,
It is supposed to work exactly like you want it to. I'm not sure what you're doing different that has it acting funny. My guess would be that somehow your web services aren't working with the controls perfectly. Make sure your parameter names exactly match those in the sample. Shawn mentioned this above, but made a slight typo. Here's what they should look like (in C# and VB):
public AtlasControlToolkit.CascadingDropDownNameValue[] GetXXXXX(string knownCategoryValues,string category){}
Imports AtlasControlToolkitPublic Function GetXXXXX(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As CascadingDropDownNameValue()End Function
If this doesn't help fix the problem, just keep posting with more details.
Thanks,
Ted
I'm not sure if the problem I'm having is similar or not, but I'm hoping someone can help me find a solution to my issue.
My webservices and atlas don't seem to want to play nicely together. My drop downs appear blank if I try to use web services to provide the data, but work fine if I use built in page methods.
Just to be sure, I copied the code for the vegetables mockup supplied here, and sure enough, if I used a webservice called listcountservice, my drop down was blank.
So I movd the code into my test page, and everything works fine. Just to be sure, my code works fine if I do the following:
<atlas:ScriptManagerID="ScriptManager1"runat="server"/><table><tr><tdalign="right">Catalog Item</td><td><asp:DropDownListID="ddlCatalogItem"runat="server"></asp:DropDownList></td></tr><tr><tdalign="right">Front Image</td><td><asp:DropDownListID="ddlFrontImage"runat="server"></asp:DropDownList></td></tr></table><atlasToolkit:CascadingDropDownID="cdd"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlCatalogItem"Category="Item"ServiceMethod="GetCatalogItems"PromptText="Select item to order"/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlFrontImage"ParentControlID="ddlCatalogItem"Category="Image"ServiceMethod="GetImages"PromptText="Select the front image"/></atlasToolkit:CascadingDropDown>and in the .vb
Imports
System.Web.ServicesImports
AtlasControlToolkitPartial
Class spellvault_testInherits System.Web.UI.Page<WebMethod()> _
PublicFunction GetCatalogItems(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue()ReturnNew CascadingDropDownNameValue() _{
New CascadingDropDownNameValue("Fruit", 0),New CascadingDropDownNameValue("Vegetable", 1)}EndFunction<WebMethod()> _
PublicFunction GetImages(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue()Dim kvAs StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)Dim ItemIdAsIntegerIf (kv.ContainsKey("Item")And Int32.TryParse(kv("Item"), ItemId))ThenIf (ItemId = 0)ThenReturnNew CascadingDropDownNameValue() _{
New CascadingDropDownNameValue("Apple", 2), _New CascadingDropDownNameValue("Pear", 3), _New CascadingDropDownNameValue("Banana", 4)}ElseIf (ItemId = 1)ThenReturnNew CascadingDropDownNameValue() _{
New CascadingDropDownNameValue("Potato", 5), _New CascadingDropDownNameValue("Lettuce", 6), _New CascadingDropDownNameValue("Corn", 7)}EndIfEndIfReturnNew CascadingDropDownNameValue() {}EndFunctionEnd
ClassBut not if I do it using the supplied web service. I'd appreciate it if anyone could give me a pointer towards where I'm apparantly misconfiguring my webservices or what not (I have tested and my web services do work fine by themselves, just not via the atlas extender)
Never mind. I eventually figured out that I needed some additional code
<
sectionname="webServices"type="Microsoft.Web.Configuration.WebServicesSection"requirePermission="false" />and
<
webServicesenableBrowserAccess="true"/>inside the microsoft.web section.
Thanks though!
No comments:
Post a Comment