Hai All,when i'm trying develop the infinite scrolling i'm facing the problem like connectionstring is not intiallizzed ,bbut my other pages are working fine with the same connection string.i'll share my page can some body helps me what is the wrong in it.and i'm sharing my handler page also .i thhink it is easy to get my problem
my DataClass.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class DataClass
{
public DataClass()
{
}
public string GetAjaxContent(int start, int end)
{
string result = string.Empty;
Dictionary<string, object> keyValPair = new Dictionary<string, object>();
keyValPair.Add("@start", start);
keyValPair.Add("@next", end);
DBHelper DBHelper = new DBHelper();
DataTable dataTable = DBHelper.GetTable("spuserdata", keyValPair);
if (dataTable.Rows.Count > 0)
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
result += string.Format(@"<tr>
<td>
<table>
<tr>
<td style='width:50px;'>{0}</td><td style='width:400px;'>{1}</td><td style='width:150px;'>{2}</td>
</tr>
</table>
</td>
</tr>", dataTable.Rows[i][0].ToString(), dataTable.Rows[i][1].ToString(), dataTable.Rows[i][2].ToString());
}
}
return result;
}
public DataTable FirstTenRecords()
{
Dictionary<string, object> keyValPair = new Dictionary<string, object>();
keyValPair.Add("@start", 0);
keyValPair.Add("@next", 10);
DBHelper DBHelper = new DBHelper();
DataTable dataTable = DBHelper.GetTable("spuserdata", keyValPair);
return dataTable;
}
}
public class Provider
{
public static SqlConnection GetConnection()
{
return new SqlConnection(ConfigurationManager.AppSettings["conn"]);
}
}
public class DBHelper
{
public DBHelper()
{
}
public DataTable GetTable(string SPName, Dictionary<string, object> SPParamWithValues)
{
SqlConnection conn;
SqlCommand cmd;
SqlDataAdapter adapter;
DataTable dataTable = new DataTable();
conn = Provider.GetConnection();
conn.Open();
cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.CommandText = SPName;
foreach (KeyValuePair<string, object> paramValue in SPParamWithValues)
{
cmd.Parameters.AddWithValue(paramValue.Key, paramValue.Value);
}
adapter = new SqlDataAdapter(cmd);
adapter.Fill(dataTable);
return dataTable;
}
}
and my handlerr.aspx is
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string startQstring = context.Request.QueryString["start"];
string nextQstring = context.Request.QueryString["next"];
if ((!string.IsNullOrWhiteSpace(startQstring)) && (!string.IsNullOrWhiteSpace(nextQstring)))
{
int start = Convert.ToInt32(startQstring);
int next = Convert.ToInt32(nextQstring);
context.Response.ContentType = "text/plain";
DataClass data = new DataClass();
context.Response.Write(data.GetAjaxContent(start, next));
}
}
public bool IsReusable {
get {
return false;
}
}
}
Thanks and Regards