I have a report that renders perfectly fine when I am populating it with data. I have complex charts, tables and a lot of data (around 20,000 memory objects). My report rendered perfectly fine untill I added a for loop for some data calculation. The for loop is as follows:
public void InsertLineBreaks(List<LineChart> inputList, int sampleInterval)
{
List<LineChart> breaklinesList = new List<LineChart> { };
for (int i = 1; i <= inputList.Count; i++)
{
if ((inputList[i].X - inputList[i - 1].X).TotalMinutes > sampleInterval)
{
LineChart breakline = inputList[i];
breakline.BreakLine = 1;
breaklinesList.Add(breakline);
}
inputList.AddRange(breaklinesList);
}
This code basically checks if every data has same interval otherwise adds a breakline. When I add this code, my reportviewer directly shows a blank page without any errors or report controls (next, print, export, etc. buttons). However, if I comment this code out, the report generates just fine without any issues.
I tried debugging the code and put a breakpoint on the data sources. I was surprised to see that the reportviewer still runs and shows a blank page despite the breakpoint. So obviously, the data is not binded and that is why the report viewer is blank.
I suspect reportviewer exceeds the memory allotted to it hence skips my code and data binding and prints blank page. Can anyone help?
The problem was not with the memory of report builder but with my code. i changed the code to the following and it worked:
public void InsertLineBreaks(List<LineChart> inputList, int sampleInterval)
{
List<LineChart> breaklinesList = new List<LineChart> { };
for (int i = 1; i <= inputList.Count; i++)
{
if ((inputList[i].X - inputList[i - 1].X).TotalMinutes > sampleInterval)
{
LineChart breakline = inputList[i];
breakline.BreakLine = 1;
breaklinesList.Add(breakline);
}
}
inputList.AddRange(breaklinesList);
}
Related
so i have an HTML table with dynamically added rows and ASP.NET text boxes. I have the rows and controls re-instantiated on page_load if the viewstate[dataonpage] = true, and I'm declaring it as true in the method that adds the rows and controls. (I need them to persist on other postbacks)
The problem is that I'm now I've added a CLEAR button that removes all of the html rows (excluding the headers) when it's clicked, and for some reason on button click it gets an index error, or if using Try/Catch it only removes half of the rows (every other row). I believe the problem is something to do with that the viewstate[dataonpage] is still "true", and the data is being re-added on page load. If i add viewstate["dataonpage"] = "false" into the clear button method, the same happens but at least this way on the second click it removes the second half of the rows.
I understand this happens because the button event handler isn't fired until after the page_load which is why it doesn't work on the first click. But what I don't fully understand is why even without this my clear button code doesn't clear all of the rows in the first place.
Any help on understanding why it doesn't work, and a work around will be greatly appreciated!
protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToString(ViewState["DataOnPage"]) == "true")
{
Getmarketdata();
}
}
protected void Getdatabtn_Click(object sender, EventArgs e)
{
ViewState["DataOnPage"] = "true";
Getmarketdata();
}
Below is method that creates adds table rows and controls:
public void Getmarketdata()
{
String url = "https://api.rightmove.co.uk/api/rent/find?index=0&sortType=1&maxDaysSinceAdded=" + Dayssinceuploadtext.Text + "&locationIdentifier=OUTCODE%5e" + Outcodetext.Text + "&apiApplication=IPAD";
Response.Write(url);
using (var webclient = new WebClient())
{
String Rawjson = webclient.DownloadString(url);
ViewState["VSMarketDataJSONString"] = Rawjson;
dynamic dobj = JsonConvert.DeserializeObject<dynamic>(Rawjson);
int NoOfHouses = dobj["properties"].Count;
Response.Write("<br />" + NoOfHouses);
for (int i = 0; i < NoOfHouses; i++)
{
System.Web.UI.HtmlControls.HtmlTableRow tRow = new System.Web.UI.HtmlControls.HtmlTableRow();
GeneratorTable.Rows.Add(tRow);
String RMlink = String.Format("https://www.rightmove.co.uk/property-to-rent/property-" + dobj["properties"][i]["identifier"].ToString()) + ".html";
HyperLink hypLink = new HyperLink();
hypLink.Text = dobj["properties"][i]["identifier"].ToString();
hypLink.Target = "_blank";
hypLink.NavigateUrl = RMlink;
using (System.Web.UI.HtmlControls.HtmlTableCell tb1 = new System.Web.UI.HtmlControls.HtmlTableCell())
{
tRow.Cells.Add(tb1);
tb1.Controls.Add(hypLink);
}
using (System.Web.UI.HtmlControls.HtmlTableCell tb2 = new System.Web.UI.HtmlControls.HtmlTableCell())
{
TextBox tbEPCe = new TextBox();
tRow.Cells.Add(tb2);
tb2.Controls.Add(tbEPCe);
String txtboxID = (("EPCETxtBox") + i);
tbEPCe.ID = txtboxID;
tbEPCe.Style.Add("background", "none"); tbEPCe.Style.Add("border", "1px solid black"); tbEPCe.Style.Add("border-radius", "2px");
}
using (System.Web.UI.HtmlControls.HtmlTableCell tb3 = new System.Web.UI.HtmlControls.HtmlTableCell())
{
TextBox tbEPCp = new TextBox();
tRow.Cells.Add(tb3);
tb3.Controls.Add(tbEPCp);
String txtboxID = (("EPCPTxtBox") + i);
tbEPCp.ID = txtboxID;
tbEPCp.Style.Add("background", "none"); tbEPCp.Style.Add("border", "1px solid black"); tbEPCp.Style.Add("border-radius", "2px");
}
using (System.Web.UI.HtmlControls.HtmlTableCell tb4 = new System.Web.UI.HtmlControls.HtmlTableCell())
{
TextBox tbBbl = new TextBox();
tRow.Cells.Add(tb4);
tb4.Controls.Add(tbBbl);
String txtboxID = (("BblTxtBox") + i);
tbBbl.ID = txtboxID;
tbBbl.Style.Add("background", "none"); tbBbl.Style.Add("border", "1px solid black"); tbBbl.Style.Add("border-radius", "2px");
}
}
}
}
Below is clear table rows method: (this is the one that isn't working)
public void ClearTableRows()
{
System.Web.UI.HtmlControls.HtmlTable Htmlgeneratortable = ((System.Web.UI.HtmlControls.HtmlTable)GeneratorTable);
int NoOfRows = Htmlgeneratortable.Rows.Count;
for (int j = 1; j < NoOfRows; j++)
{
try
{
Htmlgeneratortable.Rows.RemoveAt(j);
}
catch
{ }
}
}
I'm going to explain what's going on as you have the code written now; I don't have faith in my ability to provide an answer including the exact code changes to be made, so here is what is wrong with your current approach:
Your table, GeneratorTable exists for all clients. That doesn't mean every time someone navigates to your website a table is generated, it means that there is one table, and every client that logs in is getting that one table.
So if you add rows to it for one client, then send the table to another client, both clients will see the same table (with the rows added).
The problem is that emptying out a table is logic that has nothing to do with your back-end server. There's no reason for your server to be handling emptying a table, your server should only handle page navigations and AJAX calls pretty much, it shouldn't be changing how the webpage looks, because the server can only respond to each client one time.
What's the point in responding to a client with GeneratorTable and then updating GeneratorTable on the server? The client will never see the updates made to the table unless they're resent from the server.
You stated that you are new to this and need to learn about JS and client-side, this exercise should serve as an example of why you need to put certain code on the front-end and some code on the back-end, as there isn't really an elegeant way to do what you're looking to do with just the server.
I am having problems with setting horizontal page breaks. No matter what row I set the first page break to it ALWAYS is set the row 87
This is the code I am using. (I checked to see if I was accidentally setting the page break again below this code, but I was not) So this is all of the code I am using to setup the print settings.
int pageCount = 2;
string defprinter = null;
defprinter = xlApplication.ActivePrinter;
xlWorkSheet.ResetAllPageBreaks();
xlApplication.ActivePrinter = defprinter;
var with = xlWorkSheet.PageSetup;
with.PaperSize = Excel.XlPaperSize.xlPaperA4;
with.Orientation = Excel.XlPageOrientation.xlPortrait;
// Fit Sheet on One Page
with.Zoom = false;
with.FitToPagesWide = 1;
with.PrintArea = #"$A$1:$I$" + (pageCount * 71);
with.FitToPagesTall = pageCount;
xlWorkSheet.HPageBreaks.Add(xlWorkSheet.Range["A72"]);
xlWorkSheet.HPageBreaks.Add(xlWorkSheet.Range["A143"]);
// Normal Margins
with.LeftMargin = xlApplication.InchesToPoints(0.5);
with.RightMargin = xlApplication.InchesToPoints(0.5);
with.TopMargin = xlApplication.InchesToPoints(0.5);
with.BottomMargin = xlApplication.InchesToPoints(0.5);
I have spent the better part of two days trying all different settings with no luck. No matter what I do, the first PageBreak is always set the row 87 and not row 72.
Any suggestions would be greatly appreciated.
EDIT: Tried this code on a different PC today and it works as it should. So now the issue is identified as being something to do with what is going on in Excel on that particular machine. OS is Windows 10 BTW.
So even though it works, this is still an issue as I can't have it sporadically working on some users PC's and not on others.
I have an application that was throwing the error message below:
Invalid currentpageindex value. it must be >= 0 and the < pagecount
This issue happens if I go to the second page in my application and then try to filter the results by entering a search term.
After some research I thought I had fixed the issue by adding this line to my code
gridResult.CurrentPageIndex = 0;
So the code block now looks like this:
private void gridResult_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
gridResult.CurrentPageIndex = e.NewPageIndex;
FillGrid(tbSearch.Text);
gridResult.CurrentPageIndex = 0;
}
This stops the original issue with the error I was encountering explained above. However now if I navigate to the second page in my paging and then click to go back to the first page the data is not refreshed it just holds on to the data in the second page.
I have been struggling to find any solution for this, any ideas would be appreciated.
I have a c# windows form application.I have 2 charts in my windows form. i also have a combobox and two buttons among others. What i want is according to the text of the combobox, when i press the start button to load different graphs. So at button start event according to value of combobox i call a different function that loads the charts with what i want each time. And the second button , the stop button has the code below in order to clear the charts.
chart1.Series.Clear();
chart2.Series.Clear();
Sometimes my code runs ok but there are times that it throws the error
" A chart element with the name 'kwh_price' already exists in the 'SeriesCollection'." My code for load the chart is:
string[] seriesArray = { "kwh_price", "p_cost" };
for (int i = 0; i < seriesArray.Length; i++)
{
this.chart1.Series.Add(seriesArray[i]);
this.chart1.Series[seriesArray[i]].BorderWidth = 7;
}
Am i doing something wrong??is there something more needed in order to clear the chart?? And i don't understand why sometimes it runs ok and others not.
Put the clear code in before the load code. That way you can be sure the data is cleared before adding new data.
chart1.Series.Clear();
chart2.Series.Clear();
string[] seriesArray = { "kwh_price", "p_cost" };
for (int i = 0; i < seriesArray.Length; i++)
{
this.chart1.Series.Add(seriesArray[i]);
this.chart1.Series[seriesArray[i]].BorderWidth = 7;
}
On one web user control
public void displayFindingSection(int sectionsid,string text,string head)
{
SectionHeading.Text = head;
DataSet totImgs;
totImgs = objGetBaseCase.GetFindingsNewerImages(sectionsid);
FindingViewerlist.DataSource = totImgs;
DataBind();
SectionText.Text = text;
}
On other web user control
public void DisplayFindingsViewer(CipCaseWorkflowItem2 item)
{
FindingViewerDisplay.Visible = true;
ImageAndSimpleViewer.Visible = false;
objGetBaseCase.GetFindingsImages((Convert.ToInt32(Session["CaseId"])), item.ItemId);
FindingsViewerNew = objGetBaseCase.GetFindingViewerNewElementDetails(item.ItemId);
for (int i = 0; i < FindingsViewerNew.Count; i++)
{
FindingViwerDisplay uc = (FindingViwerDisplay)LoadControl("FindingViwerDisplay.ascx");
FindingPlaceholder.Controls.Add(uc);
uc.displayFindingSection(Convert.ToInt32(FindingsViewerNew[i].Index), FindingsViewerNew[i].Text, FindingsViewerNew[i].Title);
}
}
I am adding the all the image in user control and displaying the image, but when i am using the above code, web user control is also adding every time and one image is showing in in control what i want is all images should show in only one user control.. sectionsid is getting the image id from the database. I think prob with for loop but i am unable to solve it.. help me it that
Might be it is happening u have defined it inside the loop
FindingViwerDisplay uc = (FindingViwerDisplay)LoadControl("FindingViwerDisplay.ascx");
FindingPlaceholder.Controls.Add(uc);
On Each loop you are adding uc and calling displayFindingSection whcich ofcouse add 1 image than loop go back add a new control again and than add one image it will go on till your loop completion so add control once before loop and call just displayFindingSection in loop..
Do this,
FindingViwerDisplay uc = (FindingViwerDisplay)LoadControl("FindingViwerDisplay.ascx");
FindingPlaceholder.Controls.Add(uc);
//define here a dataTabel with three columns let say u have datatable dt
for (int i = 0; i < FindingsViewerNew.Count; i++)
{
dt.Rows.Add(Convert.ToInt32(FindingsViewerNew[i].Index), FindingsViewerNew[i].Text, FindingsViewerNew[i].Title);
}
uc.displayFindingSection(dt);
Then work out on that dt in displayFindingSection
Sorry if i am wrong...