I have a web service that wish to call, and I want to pass a parameter to it based on a value in a table cell. The table is rendered by a Repeater Control.
The idea is to show a div with data returned from the database call, performed by the webservice, when I hover over the table rows.
The javascript call looks like this:
$(document).ready(function() {
$("tr.rows").hover(function() {
//alert('Test');
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{ madvare: '" + $('span#MadLogMadVare').val() + "'}",
url: "HoverBox.asmx/GetDetails",
dataType: "json",
success: function(data) {
//alert('Success Test');
var Madvare = data.d;
$('#DetailsBox').html(
('<p><strong>' + Madvare.MadLogMadVare + "</strong><br />"))
}
});
});
});
The call never reaches the success function, so my guess is that I'm not getting the value correctly from the Table cell...
Any ideas how to get the value from the rendered Table cell?
I thought I wolud add the Webservice code:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] public class HoverBox : WebService { public HoverBox() { }
private static string _connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
[WebMethod]
public static MadLog GetDetails(string madvare)
{
MadLog _madlog = new MadLog();
string query = "SELECT * FROM frisk_madlog WHERE frisk_madlogmadvare = @frisk_madlogmadvare";
using (SqlConnection conn = new SqlConnection(_connString))
{
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.AddWithValue("frisk_madlogmadvare", madvare);
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow);
if (rdr.HasRows)
{
while (rdr.Read())
{
_madlog.MadLogID = Convert.ToInt32(rdr["frisk_madlogID"]);
_madlog.MadLogUserID = (Guid)(rdr["frisk_madloguserID"]);
_madlog.MadLogMadVare = rdr["frisk_madlogmadvare"].ToString();
_madlog.MadLogKalorier = (double)(rdr["frisk_madlogkalorier"]);
_madlog.MadLogMaengde = (double)(rdr["frisk_madlogmaengde"]);
_madlog.MadLogDato = Convert.ToDateTime(rdr["frisk_madlogdato"]);
_madlog.MadLogKategori = rdr["frisk_madlogkategori"].ToString();
}
}
}
}
return _madlog;
}
}