I am currently working on a calendar project that retrieves entries from a SQL database. The calendar is being built programmatically in a JavaScript file, where I have hardcoded the code for generating the calendar cell for a specific day (in this case, it is represented by the variable counter). All I need to do is insert the query inside the function.
JavaScript File
if (counter == 2 //2 is the Harcoded day
&& month == 8 //Hardcoded month
&& year == 2014) { //Harcoded year
PageMethods.Msg(onSuccess);
function onSuccess(response) {
alert(response);
}
htmlContent += "<div class='user'>Data retrieved from DB goes here</div>";
htmlContent += "<div class='client'>Data retrieved from DB goes here</div>";
htmlContent += "<div class='num'>Data retrieved from DB goes here</div>";
htmlContent += "<div class='status'></div>";
}
I have created a method in the Code Behind, but I am unsure of how to pass the Object Div to get the query results and set them in the Divs. Or how to access the counter value in the query to retrieve results for specific days.
Code Behind
[System.Web.Services.WebMethod]
public static string Msg()
{
return "Hello world";
string connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
using (SqlConnection myConnection = new SqlConnection(connStr))
{
myConnection.Open();
SqlCommand sqlCommand = new SqlCommand(" SELECT * FROM table",myConnection);
//Add parameters to the query
//<--- Where can I access the counter value from the JavaScript file? :(
SqlDataReader dr = sqlCommand.ExecuteReader();
if (dr != null)
{
while (dr.Read())
{
//<-- How do I set the query result to the divs here? :(
}
}
}
}