Hi My Static Method is
[WebMethod(EnableSession = true)]
public static List<Entity.Report> ChartNavigation(string type, string user, string date)
{
WebForm2 objForm = new WebForm2();
objForm.BindCVTrackerForNavigation(user, date);
List<Entity.Report> listchart = new List<Entity.Report>();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Recruitment"].ConnectionString))
{
string sqlString = "GetNumberOfCVSentForChartNavigation";
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserName", user.Replace("\"", "")));
cmd.Parameters.Add(new SqlParameter("@Date", date.Replace("\"", "")));
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (rdr.Read())
{
Entity.Report obj = new Entity.Report();
Utilities.Common.Fill(obj, rdr);
listchart.Add(obj);
}
conn.Close();
}
}
return listchart;
}
And I am calling Non static method from it. My non static method is
protected void BindCVTrackerForNavigation(string User,string Date)
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Recruitment"].ConnectionString))
{
string sqlString = "GetNumberOfCVSentForNavigation";
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserName", User.Replace("\"", "")));
cmd.Parameters.Add(new SqlParameter("@Date", Date.Replace("\"", "")));
conn.Open();
SqlDataAdapter DA1 = new SqlDataAdapter(cmd);
DA1.Fill(ds);
conn.Close();
}
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
gvCVTracker.DataSource = ds.Tables[0];
gvCVTracker.DataBind();
}
}
}
}
When datasource is apply to gvCVTracker
it throws error Object reference not set to an instance of an object.
I dont know what is the problem? Any help would be appriciated.Thanks.
您必须使用Page.LoadControl创建WebForm2的实例,以便它也可以处理控件的初始化。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.