Showing posts with label solution. Show all posts
Showing posts with label solution. Show all posts

Monday, March 26, 2012

CascadingDropDowns from bad to worse...

I was getting a [Method Error 500] on a DropDown and was combing through the posts trying to find a solution. I stripped my code down to two simple DropDowns with CascadingDropDown controls attached to them. I was able to get the top level control to populate correctly but was still getting the Eror 500 on my child DropDown. One of the posts I saw suggested making my Web Service methods Shared (I'm using VB). I tried that and now my original DropDown stopped populating at. The Web Service code isn't being reached at all. I tried removing the Shared designation from my methods but the problem has not gone away. I have cleared my IE cache and completely recreated the project. Still, I can't get a single DropDown to populate usnig a Cascading DropDown and a WebService.Here's my aspx markup:

Here's the code in my WebService: _ _ _ _Public Class Locations Inherits System.Web.Services.WebService Private Shared ConnString As String = ConfigurationManager.ConnectionStrings("Inventory").ToString() Private Shared SqlCN As New SqlConnection(ConnString) _ _ Public Shared Function GetLocations() As CascadingDropDownNameValue() Try Dim Ds As DataSet = GetLocationDs() Ds.Tables(0).DefaultView.Sort = "Text ASC" Dim Values As New List(Of CascadingDropDownNameValue) For Each Dr As DataRow In Ds.Tables(0).DefaultView.Table.Rows Values.Add(New CascadingDropDownNameValue(Dr("Text").ToString(), Dr("Value").ToString())) Next Return Values.ToArray() Catch ex As Exception Dim newEx As Exception = ex Return Nothing End Try End Function Private Shared Function GetLocationDs() As DataSet Try Dim SqlCmd As SqlCommand = SqlCN.CreateCommand() Dim PTextColumn As New SqlParameter() Dim PValueColumn As New SqlParameter() Dim PTableName As New SqlParameter() Dim SqlDA As SqlDataAdapter = New SqlDataAdapter() Dim DropDownDS As DataSet = New DataSet() Dim I As Integer = 0 With PTextColumn .DbType = DbType.String .ParameterName = "@dotnet.itags.org.TextColumn" .Value = "Location" End With With PValueColumn .DbType = DbType.String .ParameterName = "@dotnet.itags.org.ValueColumn" .Value = "Location" End With With PTableName .DbType = DbType.String .ParameterName = "@dotnet.itags.org.TableName" .Value = "HE_Locations" End With With SqlCmd .CommandType = CommandType.StoredProcedure .CommandText = "usp_GetDropDownValues" .Parameters.Add(PTextColumn) .Parameters.Add(PValueColumn) .Parameters.Add(PTableName) End With SqlDA.SelectCommand = SqlCmd If SqlCN.State <> ConnectionState.Closed Then SqlCN.Close() End If SqlCN.Open() SqlDA.Fill(DropDownDS, "Values") Return DropDownDS Catch ex As Exception Throw New DataException("GetDropDownValues failed.", ex) Return Nothing Finally SqlCN.Close() End Try End FunctionEnd ClassIf anyone has any ideas, I would sure like to hear them. I'm about ready to pull out my AJAX manual and roll my own. I have lost a whole day on this. Even if I get my original DropDown working I still have the ubiquitous Method Error 500 to deal with.Btw, the code in my Catch block was simply a place to put a breakpoint for debugging so I could read exception mesage if there was one. There wasn't.Thanks!

Well, that didn't come out very well, did it?

Actually, nevermind. For some reason, after using the I.E. Devloper Toolbar, scripting in I.E. was disabled. I also figured out my Method Error 500 problem. I realize now that the parameters in the method signature have to match the example exactly - even the case. I assumed that wouldn't matter since I'm using VB.

Thanks.

Saturday, March 24, 2012

CascadingDropDown, SelectedValue in a bound form

Hey folks,

I don't know if it's been addressed, but I couldn't find the solution.

I need to databind selectedValue of a cascading dropdown. Since TargetProperties cannot be databound using <#% #> syntax, I use DataBinding event handler:

 <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true" /> <asp:FormView ID="frm1" runat="server" DefaultMode="insert"> <InsertItemTemplate> <asp:Button ID="btnToggle" runat="server" OnClick="btnToggle_OnClick" Text="Toggle dropdown panel" /> <asp:Panel ID="pnlDropdown" runat="server" Visible="false"> <asp:DropDownList ID="ddl1" runat="server" /> <atlasToolkit:CascadingDropDown runat="server" ID="cdd1" OnDataBinding="cdd1_DataBinding"> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddl1" ServiceMethod="GetOptions" PromptText="--Select--" Category="Options" /> </atlasToolkit:CascadingDropDown> </asp:Panel> </InsertItemTemplate> </asp:FormView> </div> </form>

With the following codebehind:

protected void btnToggle_OnClick(object sender, EventArgs args) { Panel pnlDropdown = (Panel) ((Control)sender).Parent.FindControl("pnlDropdown" ); pnlDropdown.Visible = !pnlDropdown.Visible; }protected void cdd1_DataBinding(object sender, EventArgs args) { CascadingDropDown cdd1 = (CascadingDropDown)sender; cdd1.TargetProperties[0].SelectedValue ="1"; } [WebMethod]public CascadingDropDownNameValue[] GetOptions(string knownCategoryValues,string category) { CascadingDropDownNameValue[] cddValues =new CascadingDropDownNameValue[] {new CascadingDropDownNameValue("one","1"),new CascadingDropDownNameValue("two","2") };return cddValues; }

The problem exhibits itself only if the CascadingDropDown is originally hidden.

Obviously, this isn't the production code, but it models the behaviour precisly.

Any way to solve it?

Thanks in advance,

ET

Sorry, I forgot to state the actual problem, thespecified SelectedValue is ignored if the dropdown is not visible at the time of binding. Why?

et_td:

Hey folks,

I don't know if it's been addressed, but I couldn't find the solution.

I need to databind selectedValue of a cascading dropdown. Since TargetProperties cannot be databound using <#% #> syntax, I use DataBinding event handler:

 <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true" /> <asp:FormView ID="frm1" runat="server" DefaultMode="insert"> <InsertItemTemplate> <asp:Button ID="btnToggle" runat="server" OnClick="btnToggle_OnClick" Text="Toggle dropdown panel" /> <asp:Panel ID="pnlDropdown" runat="server" Visible="false"> <asp:DropDownList ID="ddl1" runat="server" /> <atlasToolkit:CascadingDropDown runat="server" ID="cdd1" OnDataBinding="cdd1_DataBinding"> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddl1" ServiceMethod="GetOptions" PromptText="--Select--" Category="Options" /> </atlasToolkit:CascadingDropDown> </asp:Panel> </InsertItemTemplate> </asp:FormView> </div> </form>

With the following codebehind:

protected void btnToggle_OnClick(object sender, EventArgs args) { Panel pnlDropdown = (Panel) ((Control)sender).Parent.FindControl("pnlDropdown" ); pnlDropdown.Visible = !pnlDropdown.Visible; }protected void cdd1_DataBinding(object sender, EventArgs args) { CascadingDropDown cdd1 = (CascadingDropDown)sender; cdd1.TargetProperties[0].SelectedValue ="1"; } [WebMethod]public CascadingDropDownNameValue[] GetOptions(string knownCategoryValues,string category) { CascadingDropDownNameValue[] cddValues =new CascadingDropDownNameValue[] {new CascadingDropDownNameValue("one","1"),new CascadingDropDownNameValue("two","2") };return cddValues; }

The problem exhibits itself only if the CascadingDropDown is originally hidden.

Obviously, this isn't the production code, but it models the behaviour precisly.

Any way to solve it?

Thanks in advance,

ET


As a workaround, I found that setting SelectedValue in an FormView.ItemCreated event handler works.

Cheers,

ET

CascadingDropDown, problems selecting values

Hello,

I did some research but couldn't find a solution and I hope you can help me.
The DropDownList (there are more, but one will suffice) is populated correctly, at least when I click on it.

<asp:HiddenField ID="SomeID" OnValueChanged="VC_Method" runat="server" />
<div id="hiddenForm" style="display :none">
<asp:UpdatePanel ID="DetailUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="False" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ProjectDDL" runat="server"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="CDD0" TargetControlID="ProjectDDL" Category="Project" ServicePath="CDD.asmx" ServiceMethod="GetProjects" runat="server" />

So now what this should do is, when clicking on a Link the DetailUpdatePanel becomes visible and the VC_Method of the HiddenField is executed and in this Method I want to select a certain item of the DDL. But there are no values to choose from. Now my question is, becomes the CDD only populated when I click on it and if so, how can I populate it beforehand?

Thanks in advance.

I solved the problem above, but I'm now terribly stuck.

After the user selected one item from the first dropdownlist, the second becomes active etc. Now the user decides to cancel the task and for wathever reason he starts anew. My problem now is, that I want to reset the cascading dropdownlist on client side, so that the user can only select items from the first dropdownlist. For this purpose a javascript function should be executed. I can set the dropdownlist to the value I want and also the cascading dropdownlist, but it won't affect the second and third. Thus they stay active with wrong information.

I have tried now for one day hand havn't got a clue. Please help me..

EDIT:corrected some errors


Hi Twinkybot,

My understanding of your issue is that you want the second CascadingDropDown not change while you selected the first CascadingDropDown. If I has misunderstood, please feel free to let me know.

Based on this knowledge, I think you can remove the handlers of the first CascadingDropDown and then remove the second CascadingDropDown's _parentChangeHandler. Here is the sample.

<%@. Page Language="C#" EnableEventValidation="false" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
<script runat="server"
protected void Page_Load(object sender, EventArgs e)
{

}
</script
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="../WebService/CityServiceOledb.asmx" InlineScript="true" />
</Services>
</asp:ScriptManager>
State:<asp:DropDownList runat="server" ID="dlState">
</asp:DropDownList>
City:
<asp:DropDownList runat="server" ID="dlCity" AutoPostBack="true">
</asp:DropDownList>

<cc1:CascadingDropDown ID="CascadingDropDown1" BehaviorID="myCDEState" runat="server" TargetControlID="dlState"
Category="State" ServicePath="../WebService/CityServiceOledb.asmx" ServiceMethod="GetStates" LoadingText="[Loading...]" PromptText="Please select state" UseContextKey="true" ContextKey="0,0">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2" BehaviorID="myCDECity" runat="server" TargetControlID="dlCity" ParentControlID="dlState"
Category="City" PromptText="Select a city" ServicePath="../WebService/CityServiceOledb.asmx"
ServiceMethod="GetCities" LoadingText="Load Text..." >
</cc1:CascadingDropDown>

<input id="Button2" type="button" value="remove" onclick="removeCascading();"/>
<asp:Button ID="Button1" runat="server" Text="Button" />

<script type="text/javascript" language="javascript">
function removeCascading(){
$find("myCDEState").dispose();
$removeHandler($find("myCDECity")._parentElement, "change", $find("myCDECity")._parentChangeHandler);
$get("Button2").disabled = true;
}
</script>
</form>
</body>
</html>

Best regards,

Jonathan


Yes, I think you misunderstood. I want the second and third CascadingDropDown to change according to the selcetion of the first. But the Problem is, that it doesn't.

I try to explain my problem better. The user selects one item in the first DropDownList. The second becomes updated and the user is able to select one item. Now he cancels the changes and restarts the procedure.

What I want now is, that after hitting the cancel-Button, the DropDownLists must reset. I.e. in a Javascript I set the selectedIndex for the first DropDownList to 0. Corresponding to this selection the second and third should now change themselves, but it doesn't happen.

<asp:DropDownList ID="ProjectDropDownList" runat="server"></asp:DropDownList><ajaxToolkit:CascadingDropDown ID="CascadingDropDown0" TargetControlID="ProjectDropDownList" Category="Project" PromptText="Foo" ServicePath="~/CDD.asmx" ServiceMethod="GetProjects" runat="server" /><asp:DropDownList ID="TaskDropDownList" runat="server"></asp:DropDownList><ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" TargetControlID="TaskDropDownList" ParentControlID="ProjectDropDownList" Category="Task" PromptText="Foo" ServicePath="~/CDD.asmx" ServiceMethod="GetTaskForProject" runat="server" /> <asp:DropDownList ID="TaskShortDescriptionDropDownList" runat="server"></asp:DropDownList><ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" TargetControlID="TaskShortDescriptionDropDownList" ParentControlID="TaskDropDownList" Category="TaskDescription" PromptText="Foo" ServicePath="~/CDD.asmx" ServiceMethod="GetDescriptionForTask" runat="server" />
function clearForm(){ var projectDDL = document.getElementById('<%= ProjectDropDownList.ClientID%>'); projectDDL.selectedIndex = 0; //Here must be something to activate the cascade}

I found a solution and I will post this for other desperate people.

projectDropDownList.options[0] = new Option(projectName, projectId, true, false);
taskCascade._onParentChange(null, false);

CascadingDropDown with a database

I have read several similar post but yet no solution

Hello I am tryingto use Ajax CascadingDropDown with a database.

My database structure is:

IssueID(PK)
GroupID
ParentIssueID
IssueName


There are 3 dropdown list.
The first dropdown list retrieves data from the datble with parent ID = -1.
While the second drop down list retrieves it info based on the selected value (ID) of the first dropdownlist.

say we have in the table:

IssueID GroupID ParentIssueID IssueName
1 1 -1 Housing
2 1 1 Electronics
3 2 -1 Garden
4 1 2 Microwave

So, in the case the first dropdown retrives all data from the table with (ParentIssueID= -1) so here we have: Housing and Garden. both IssueIS and IssueName are returned.

Onselecting (say housing), the second dropdown retrieves any row with -> ParentIssueID = IssueID(value of ddl) of the selected value is the first dropdown. Here we have Electronics retured.

The third dropdown returns the list of rows based of the value of the selected ddl. Here we have Microwave.
Thus we have:
First ddl: Housing
Second ddl: Electronics
Third ddl: Microwave


Below is my web method:

<WebMethod()> _
Public Function GetMainIssue(ByVal knownCategoryValues As Integer, ByVal category As String) As CascadingDropDownNameValue()
Dim maindepth As Integer = 1

Dim mainIssueAdapter As New mainIsseDataTableAdapters.GetDepthTableAdapter()
Dim mainIssue As mainIsseData.GetDepthDataTable = mainIssueAdapter.GetMainIssue(maindepth)
Dim values As New List(Of CascadingDropDownNameValue)()

For Each dr As DataRow In mainIssue
Dim IssueName As String = DirectCast(dr("IssueName"), String)
Dim IssueID As Integer = CInt(dr("IssueID"))
values.Add(New CascadingDropDownNameValue(IssueName, IssueID))
Next

Return values.ToArray()

End Function


<WebMethod()> _
Public Function GetSubIssue(ByVal knownCategoryValues As Integer, ByVal category As String) As CascadingDropDownNameValue()

Dim kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim IssueID As Integer

If Not kv.ContainsKey("mainIssue") OrElse Not Int32.TryParse(kv("mainIssue"), IssueID) Then
Return Nothing
End If

Dim subIssuesAdapter As New subIssueDataTableAdapters.GetAllCategoryTableAdapter()
Dim subIssue As subIssueData.GetAllCategoryDataTable = subIssuesAdapter.GetSubIssue(IssueID)

Dim values As New List(Of CascadingDropDownNameValue)()

For Each dr As DataRow In subIssue
values.Add(New CascadingDropDownNameValue(DirectCast(dr("IssueName"), String), dr("IssueID").ToString()))
Next

Return values.ToArray()

End Function


In my aspx file I have
<asp:DropDownList id="drpMainCategory" runat="server">

<cc1:cascadingdropdown id="CascadingDropDown2" runat="server" loadingtext="[Loading...]"
prompttext="Please select a Main Issue" servicepath="../UpdateDropDown.asmx"
targetcontrolid="drpMainCategory" Category="getmain" ServiceMethod="GetMainIssue"></cc1:cascadingdropdown>

I get an error(500 or 12030) when I run it.
Also, I cant figure out what exactly the category field is for <cc1:cascadingdropdown control. how do I optain it. Any comments or similar code to help would be greatly appreciated.
Thanks

Please refer to this thread: http://forums.asp.net/t/1122659.aspx