Quantcast
Viewing latest article 15
Browse Latest Browse All 20

Re: dynamic Filter ( Using multiple drop down list)

ListBox is working now on interface and I was able to pass the values from interface to code behind but I am getting error when I am trying to filter on the data even on a single selection. I am getting following error below. I also have provided the source code behind for both before and after added your suggestion. I commented out my source code after I added yours. I put the changes in Bold. 

I do appreciate your assistance.

Server Error in '/' Application.


Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 412:            finally
Line 413:                {Line 414:                dataSet.Dispose();Line 415:                dataSet = null;
Line 416:                adapter.Dispose();


Source File: C:\Users\montadar\Documents\Visual Studio 2015\Projects\PledgeReport\PledgeReport\Default.aspx.cs   Line:414

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   PledgeReport.Default.GetData(DateTime start, DateTime end, String campaign) in C:\Users\montadar\Documents\Visual Studio 2015\Projects\PledgeReport\PledgeReport\Default.aspx.cs:414
   PledgeReport.Default.GetData() in C:\Users\montadar\Documents\Visual Studio 2015\Projects\PledgeReport\PledgeReport\Default.aspx.cs:301
   PledgeReport.Default.btnCalculate_Click(Object sender, EventArgs e) in C:\Users\montadar\Documents\Visual Studio 2015\Projects\PledgeReport\PledgeReport\Default.aspx.cs:161
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9659822
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639

// get segmment

protected void GetSeg(){
string str = base.Request.QueryString["OB"];
string str2 = base.Request.QueryString["Alias"];
string cObAlias = "";
if (string.IsNullOrEmpty(str))
{
str = ConfigurationManager.AppSettings["ObjectBroker"];
}
OleDbConnection connection = new OleDbConnection(AmAccess.GetObConnectionString(str, ref cObAlias));
connection.Open();
OleDbCommand selectCommand = new OleDbCommand("clients.dbo.spx_CampaignSegments", connection)
{
CommandType = CommandType.StoredProcedure,
CommandTimeout = connection.ConnectionTimeout
};

selectCommand.Parameters.AddWithValue("@campaignId", this.ddlCampaigns.SelectedItem.Value);
selectCommand.Parameters.AddWithValue("@segment", ConfigurationManager.AppSettings["SegmentField"]);
OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
this.lbSegments.DataSource = dataSet.Tables[0];
this.lbSegments.DataValueField = "STATE";
this.lbSegments.DataTextField = "STATE";
this.lbSegments.DataBind();
if (this.CheckConfigurationOn("AllowAllSegments"))
{
ListItem item = new ListItem("All", "All");
this.lbSegments.Items.Insert(0, item);
item = new ListItem("None", "_x_none_x_");
this.lbSegments.Items.Insert(0, item);
}
selectCommand.Dispose();
selectCommand = null;
dataSet.Dispose();
dataSet = null;
connection.Close();
}

// populate the data based on single or multiple selection

protected bool GetData(DateTime start, DateTime end, string campaign)
{
bool flag = false;
OleDbConnection connection = null;
OleDbCommand selectCommand = null;
OleDbDataAdapter adapter = null;
DataSet dataSet = null;
string str = base.Request.QueryString["OB"];
string str2 = base.Request.QueryString["Alias"];
string cObAlias = "";
if (string.IsNullOrEmpty(str))
{
str = ConfigurationManager.AppSettings["ObjectBroker"];
}
string obConnectionString = AmAccess.GetObConnectionString(str, ref cObAlias);
try
{
connection = new OleDbConnection(obConnectionString);
connection.Open();
selectCommand = new OleDbCommand("clients.dbo.spx_AmountStatsReport11", connection)
{
CommandType = CommandType.StoredProcedure,
CommandTimeout = connection.ConnectionTimeout
};
selectCommand.Parameters.AddWithValue("@start", start);
selectCommand.Parameters.AddWithValue("@end", end);
if (string.IsNullOrEmpty(campaign))
{
if (this.ddlCampaigns.SelectedItem.Text == "All")
{
selectCommand.Parameters.AddWithValue("@campaignId", DBNull.Value);
selectCommand.Parameters.AddWithValue("@campaign", DBNull.Value);
selectCommand.Parameters.AddWithValue("@segment", DBNull.Value);
selectCommand.Parameters.AddWithValue("@downloadDescriptions", DBNull.Value);
}
else
{

string c = "@campaign =";
string s = "@segment =";
// add selected campaign
c += ddlCampaigns.Items[ddlCampaigns.SelectedIndex].Value;
// get selected segmets
int[] selectedsegments = lbSegments.GetSelectedIndices();
// add selected segments to s
for (int cnt =0; cnt < selectedsegments.Length; cnt++)
{
s += lbSegments.Items[selectedsegments[cnt]].Text + ",";
}
// display
lbSegments.Text = c + " | " + s.Trim(',');
//selectCommand.Parameters.AddWithValue("@campaignId", this.ddlCampaigns.SelectedValue);
//selectCommand.Parameters.AddWithValue("@campaign", DBNull.Value);
//selectCommand.Parameters.AddWithValue("@segment", this.ddlSegments.SelectedValue);
//selectCommand.Parameters.AddWithValue("@segment", this.lbSegments.SelectedValue);
//selectCommand.Parameters.AddWithValue("@downloadDescriptions", this.ddDwnlDscrp.SelectedValue);
}
}
else if (campaign == "All")
{
selectCommand.Parameters.AddWithValue("@campaignId", DBNull.Value);
selectCommand.Parameters.AddWithValue("@campaign", DBNull.Value);
selectCommand.Parameters.AddWithValue("@segment", DBNull.Value);
selectCommand.Parameters.AddWithValue("@downloadDescriptions", DBNull.Value);
}
else
{
selectCommand.Parameters.AddWithValue("@campaignId", DBNull.Value);
selectCommand.Parameters.AddWithValue("@campaign", campaign);
selectCommand.Parameters.AddWithValue("@segment", DBNull.Value);
selectCommand.Parameters.AddWithValue("@downloadDescriptions", DBNull.Value);
}
adapter = new OleDbDataAdapter(selectCommand);
dataSet = new DataSet();
adapter.Fill(dataSet);
if (dataSet.Tables[0].Rows.Count > 0)
{
this.m_Data = "1";
flag = true;
}
if (this.CheckConfigurationOn("RemoveTotalRows"))
{
if (dataSet.Tables[0].Rows.Count > 0)
{
dataSet.Tables[0].Rows[dataSet.Tables[0].Rows.Count - 1].Delete();
}
if (dataSet.Tables[1].Rows.Count > 0)
{
dataSet.Tables[1].Rows[dataSet.Tables[1].Rows.Count - 1].Delete();
}
}
this.gvSummary.DataSource = dataSet.Tables[0];
this.gvSummary.DataBind();
this.GridView1.DataSource = dataSet.Tables[1];
this.GridView1.DataBind();
this.SaveColumnNames(this.gvColumnNames, dataSet.Tables[1]);
this.SaveColumnNames(this.gvColumnNamesSummary, dataSet.Tables[0]);
this.SetRefreshTimer();
}
catch (Exception exception)
{                                                                                                 // Wim, it catches the error here
this.m_Error = exception.Message;
this.m_Error = this.m_Error + exception.StackTrace;
this.m_Error = this.m_Error.Replace(@"\", @"\\");
this.m_Error = this.m_Error.Replace("'", @"\'");
this.m_Error = Regex.Replace(this.m_Error, @"\s+", " ").Trim();
this.m_Error = base.Server.HtmlEncode(this.m_Error);
}
finally
{
dataSet.Dispose();
dataSet = null;
adapter.Dispose();
adapter = null;
selectCommand.Dispose();
selectCommand = null;
connection.Close();
connection = null;
}
return flag;
}

// get data table parameters on start time, end time, campaign

protected DataTable GetDataTableParams(DateTime? start, DateTime? end, string campaign)
{
string text = string.Empty;
DataTable table = new DataTable();
table.Clear();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Value", typeof(string));
DataRow row = table.NewRow();
row[0] = "Start";
if (start.HasValue)
{
row[1] = start.Value.ToString(this.m_FormatDate + " " + this.m_FormatTime);
}
else
{
row[1] = this.GetStartDateTime().ToString(this.m_FormatDate + " " + this.m_FormatTime);
}
table.Rows.Add(row);
row = table.NewRow();
row[0] = "End";
if (end.HasValue)
{
row[1] = end.Value.ToString(this.m_FormatDate + " " + this.m_FormatTime);
}
else
{
row[1] = this.GetEndDateTime().ToString(this.m_FormatDate + " " + this.m_FormatTime);
}
table.Rows.Add(row);
row = table.NewRow();
row[0] = "Campaign";
if (!string.IsNullOrEmpty(campaign))
{
text = campaign;
}
else
{
text = this.ddlCampaigns.SelectedItem.Text;
}
if (text == "0")
{
text = "All";
}
row[1] = text;
table.Rows.Add(row);
row = table.NewRow();
row[0] = "Segment";
try
{
// text = this.ddlSegments.SelectedItem.Text;
text = this.lbSegments.SelectedItem.Text;
}
catch (Exception)
{
}if (text == "")

{
text = "All";
}
row[1] = text;
table.Rows.Add(row);
return table;
}


Viewing latest article 15
Browse Latest Browse All 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>