I have a dropdownlist that I use jquery ajax to make a call to a webmethod. My intended solution is to update all the data fields on the cuurent page based on the dropdown selected index using ajax.
function getDBInfo()
{
var mySelectedIndex = $("#<%=dblParameter.ClientID%>").val(); //id name for dropdown list
$.ajax({
type:"POST",
url:"/Manage/Details.aspx?param=",
data:{}
contentType:application/json; charset=utf-8",
dataType:"json"
success: function(data)
{
//this is what I am trying to accomplish but not sure how I should handle the webservice method to do this or if I am even doing it right so far
$("#<%=txtParameter.ClientID%>;").text(data.Parameter);
$("#<%=txtName.ClientID%>;").text(data.Name);
$("#<%=txtSSN.ClientID%>;").text(data.SSN);
//etc....
}
});
}
then in my code behind I have my page method
protected void Page_Load(object sender, EventArgs e)
{
dblParameter.Attributes.Add("onchange","getDBInfo");
}
[WebMethod]
public static DataRowView getDBInfo(string param)
{
ConnectionStringSettings conn = ConfiguationManager.ConnectionStrings["MasterDBConnectionString"];
SQLDataSource Details = new SqlDataSource(conn.ConnectionString, "SELECT * FROM [tblInfo] WHERE ([ParamID] = "+param);
DataRowView db = (DataRowView)Details.Select(DataSourceSelectArguments.Empty);
return db;
}
What am I doing wrong because in my javascript calling data.Name or data.Parameter won’t work. Should it be data[“Parameter”] instead? or am I way off base here
Edit1:
I changed a lot of my code around here is what I have and I am now its working
$(document).ready(function(){
$("#<%=dblParameter.ClientID%>").change(function(){
var myparam= $("#<%=dblParameter.ClientID%>").val(); //id name for dropdown list
$.ajax({
type:"POST",
url:"Details.aspx/getDBInfo",
data:'{param:"'+myparam+'"}',
contentType:application/json; charset=utf-8",
success: function(data)
{
alert(data.d)
}
});
});
});
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string getDBInfo(string param)
{
MyMainClass myInit = new MyMainClass();
string target= myInit.GetInfo(param);
return target;
}
This is what worked: