Hi All,
Im populating a DropDownList based on selection of another DropDowList.
Here is my code :
<script language="javascript" type="text/javascript">
$(document).ready(function() {
InitJQuery();
});
// this function will be called after the UpdatePanel finishes processing and set up jQuery again
function pageLoad() {
InitJQuery();
}
function InitJQuery()
{
$(".ParentList").bind("change", function()
{
var selectedValue = $(this).val();
var ElementId = this.id;
var first = ElementId.lastIndexOf('_');
var second = ElementId.substring(first,0);
var last = ElementId.substring(ElementId.length,first);
var PrimaryRoleId = last.replace("_","");
var SubCategoryId = second + "_sub_" + PrimaryRoleId;
var select = $("#" + SubCategoryId);
select.append("<option>please wait..</option>");
$.ajax({
type: "POST",
url: "http://<%=PortalAlias.HTTPAlias%>/Services/ACWebSvc.asmx/getChildData",
data: "{'id':'" + PrimaryRoleId + "','selectedValue':'" + selectedValue + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response)
{
var dataList = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
select.empty();
if(dataList.length == 0)
{
select.append("<option class='ddheader'value='0'>-N/A-</option>");
}
else
{
for (var i = 0; i < dataList.length; i++)
{
select.append("<option class='ddheader'>" + dataList[i].ListName + "</option>");
}
}
},
error: function(xhr)
{
alert(xhr.statusText);
}
});
});
}
</script>
<tr>
<td>
<asp:DropDownList ID="acListPrimaryRole" runat="server" CssClass="ParentList" Width="150px">
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="acListPrimaryCategory" runat="server" CssClass="ParentList" Width="150px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="sub_acListPrimaryRole" CssClass="ChildList" runat="server" Width="150px">
<asp:ListItem Text="-Select Sub Role-" Value="0" Selected="True"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="sub_acListPrimaryCategory" CssClass="ChildList" runat="server" Width="150px">
<asp:ListItem Text="-Select Sub Category-" Value="0" Selected="True"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
My WebService:
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class ACWebSvc
'Inherits System.Web.Services.WebService
Inherits Entities.Modules.PortalModuleBase
Dim _prfController As ProfileController
<WebMethod()> _
Public Function getChildData(ByVal id As String, ByVal selectedValue As String) As List(Of dataList)
Dim _prfController As ProfileController = New ProfileController
Dim dsChild As DataSet = _prfController.Profile_GetSecondaryList(selectedValue, id)
Dim l As New Generic.List(Of dataList)
Dim e As New dataList("0", "Select")
For Each row As DataRow In dsChild.Tables(0).Rows
e = New dataList(row("ListId"), row("ListName"))
l.Add(e)
Next
Return l
End Function
Im Binding data to first dropdown list statically.
Its working fine , im able to bind the data to second dropdownlist on selection of firstdropdown list ,
This is for some search functionality ,on click if button on this page im populating some results ,But problem is im losing the selection(second list) after postback .
How to get that selection on post back ?