.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Ava Aiden
Imran Ghani
Thomas Shaw

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Cascading dropdown problem

Posted By: Subha     Posted Date: July 18, 2010    Points:2   Category :ASP.Net
I have use the below coding to bind the data into the dropdownlist with in gridview.The data bind only in cascadingdropdown1 not in cascadingdropdown2.when i click the cascadingdropdown1 it will simply generate method error 500.
<asp:GridView runat="server" ID="gdViewStaff" DataKeyNames ="Allocate_id" CssClass ="MyGridView">
<HeaderStyle CssClass="MyGridView_Header" />
<PagerStyle CssClass="MyGridView_PagerStyle" />

<Columns >

<asp:TemplateField HeaderText ="Department" visible="false" >
<EditItemTemplate >
<asp:DropDownList runat="server" ID="ddleditdept" >
<%-- <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server"
TargetControlID ="ddleditdept"
PromptText="-Select Department-"
LoadingText="Loading Department.."
<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID ="ddleditdept"
Category ="Department_Name" ServiceMethod="Fill_Dept" ServicePath="Cascading.asmx">
<asp:TemplateField HeaderText="StaffName" Visible ="false">
<asp:DropDownList runat="server" ID="ddleditstaff">

<cc1:CascadingDropDown ID="CascadingDropDown2" runat="server"
TargetControlID ="ddleditstaff"
Category ="name" ContextKey ="ddleditdept" UseContextKey ="true" ParentControlID ="ddleditdept"

<asp:TemplateField HeaderText ="Staff_ID" Visible ="false" >
<EditItemTemplate >
<asp:TextBox ID="staffid1" runat="server"></asp:TextBox>
<asp:Label ID="staffid" runat="server" Visible ="false" Text='<%#Bind("Staff_ID") %>' ></asp:Label>

<asp:TemplateField HeaderText ="Staff_Name" Visible ="false" >
<EditItemTemplate >
<asp:TextBox ID="staffname1" runat="server"></asp:TextBox>
<asp:Label ID="staffname" runat="server" Visible ="false" Text='<%#Bind("Staff_Name") %>' ></asp:Label>

<asp:TemplateField HeaderText ="Subj" Visible ="false" >
<EditItemTemplate >
<asp:TextBox ID="subj1" runat="server"></asp:TextBox>
<asp:Label ID="subj" runat="server" Visible ="false" Text='<%#Bind("Subj") %>' ></asp:Label>

<asp:TemplateField HeaderText ="Allocate" Visible ="false" >
<EditItemTemplate >
<asp:TextBox ID="Allocate1" runat="server"></asp:TextBox>
<asp:Label ID="Allocate" runat="server" Visible ="false" Text='<%#Bind("Allocate_id") %>' ></asp:Label>

<asp:TemplateField HeaderText ="Batch" Visible ="false" >
<EditItemTemplate >
<asp:TextBox ID="Batch1" runat="server"></asp:TextBox>
<asp:Label ID="Batch" runat="server" Visible ="false" Text='<%#Bind("Batch") %>' ></asp:Label>

<asp:CommandField EditText="Edit" UpdateText="Update" HeaderText="Edit" DeleteText="Delete"
ShowEditButton="true" ValidationGroup="valgrid" ShowDeleteButton="true" >
<ControlStyle />

Webservice code:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Specialized
Imports AjaxControlToolkit
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService

Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Dim da As New SqlDataAdapter()
Dim ds As New DataSet

Dim strsql As String
<WebMethod()> Public Function Fill_Dept(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
con.ConnectionString = ConfigurationManager.AppSettings.Item("ConnectionInfo")
cmd = New SqlCommand("select * from Adm_department", con)
Dim da As New SqlDataAdapter()
Dim ds As New DataSet()
da.SelectCommand = cmd
da.Fill(ds, "test")
'Return ds
Dim countryNames As New List(Of CascadingDropDownNameValue)()
For Each dRow As DataRow In ds.Tables(0).Rows
Dim deptID As Integer = dRow("Department_ID").ToString()
Dim deptname As String = dRow("Department_Name").ToString()
countryNames.Add(New CascadingDropDownNameValue(deptname, deptID))

Return countryNames.ToArray()
End Function
<WebMethod()> Public Function Fill_Staff(ByVal knownCategoryValues As String, ByVal category As String, ByVal contextKey As String) As CascadingDropDownNameValue()
Dim kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim UpperCatlevelID As String = category

cmd = New SqlCommand("select * from Staffbio where dept=@dept", con)
cmd.Parameters.Add(New SqlParameter("@dept", UpperCatlevelID))
Dim da As New SqlDataAdapter()
Dim ds As New DataSet()
da.SelectCommand = cmd
da.Fill(ds, "test")

Dim countryNames As New List(Of CascadingDropDownNameValue)()
For Each dRow As DataRow In ds.Tables(0).Rows
Dim deptName As String = dRow("name").ToString()
Dim deptId As String = dRow("dept").ToString()
countryNames.Add(New CascadingDropDownNameValue(deptName, deptId))
Return countryNames.ToArray()
End Function
End Class

How can i resolve the problem.

Author: BangaruBabuPureti             
Posted Date: July 22, 2010     Points: 5   

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend