Hi all,
I have small problem in Json. In the code below
loadEmployeeCars($("select option:selected").val())
is not executing.
If I want to execute to the the method what should I do?
ASPX:
<script language="javascript" type="text/javascript">
$(function() {
var $ddl = $("select[name$=ddlEmployee]");
var $ddlCars = $("select[name$=ddlEmployeeCars]");
$ddl.focus();
$ddl.bind("change keyup", function() {
if ($(this).val() != "0") {
loadEmployeeCars($("select option:selected").val());
$ddlCars.fadeIn("slow");
} else {
$ddlCars.fadeOut("slow");
}
});
});
function loadEmployeeCars(selectedItem) {
$.ajax({
type: "POST",
url: "DropdowndemoJson.aspx/getdataset",
data: "{docid: " + selectedItem + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function Success(data) {
printEmployeeCars(data.d);
}
});
}
function printEmployeeCars(data) {
$("select[name$=ddlEmployeeCars] > option").remove();
for (var i = 0; i < data.length; i++) {
$("select[name$=ddlEmployeeCars]").append(
$("<option></option>").val(data[i].docid).html(data[i].docname)
);
}
}
</script>
<asp:dropdownlist id="ddlEmployee" runat="server" appenddatabounditems="true" xmlns:asp="#unknown">
<asp:listitem text="(Please Select)" value="0" selected="True" />
</asp:dropdownlist>
<asp:dropdownlist id="ddlEmployeeCars" runat="server" xmlns:asp="#unknown">
</asp:dropdownlist>
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
fillemp();
fillempcars();
}
private void fillempcars()
{
string s2= "select * from deptmaster";
SqlDataAdapter ad1 = new SqlDataAdapter(s2, con);
DataSet ds2= new DataSet();
ad1.Fill(ds2);
ddlEmployeeCars.DataTextField = "deptid";
ddlEmployeeCars.DataValueField = "deptname";
ddlEmployeeCars.DataSource = ds2;
ddlEmployeeCars.DataBind();
}
private void fillemp()
{
string s = "select * from docmaster";
SqlDataAdapter ad1 = new SqlDataAdapter(s,con);
DataSet ds1 = new DataSet();
ad1.Fill(ds1);
ddlEmployee.DataTextField = "docname";
ddlEmployee.DataValueField = "docname";
ddlEmployee.DataSource = ds1;
ddlEmployee.DataBind();
}
public void getdataset(int deptid)
{
string query = "select d.deptid,d.deptname from deptmaster d, docmaster doc where doc.deptid=d.deptid and doc.docid='"+ddlEmployee.SelectedValue+"' ";
SqlDataAdapter ad = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
ad.Fill(ds);
}
Best Regards,
Thiru