itextsharp leaving first page empty and printing table conent in following table - asp.net

I have three part in my PDF generating document using iTextSharp library.
The Header and footer I am printing using OnEndPage() of PdfPageEventHelper class. The header and footer printing well in all pages.But problem in printing large table content from middle of the page.
Now, I am facing problem when I have more that 100 table rows content to print on middle of the page.
On first page (middle of the page) I am printing table with more than 100 rows, but in this case it leave the first page empty and start printing table content on second page. Here is my table that I am trying to print on first page
PdfPTable table = new PdfPTable(5);
table.HeaderRows = 1;
table.SplitLate = false;
table.SplitRows = false;
table.SetTotalWidth(new float[] { 100, 75, 75, 75, 75 });
table.LockedWidth = true;
for (int i = 0; i < 150; i++)
{
PdfPCell cell = new PdfPCell(new phrase());
cell.Colspan = 5;
table.AddCell(cell);
}
I am using iTextSharp version: 5.4.5.0
Is there any configuration need to do, that will prevent page break?
But I am getting actual result in this format

Allow me to comment on these two lines:
table.SplitLate = false;
table.SplitRows = false;
The first line tells iTextSharp what it should do if a row doesn't fit a page. If you set this value to false, rows will be split late. For instance: you have a big row that doesn't fit the current page. In that case, the row will be forwarded to the next page. If it still doesn't fit the page, then another decision needs to be made: should the row be split or not?
The second line gives iTextSharp the answer to that question. If the value of SplitRows is true, then the row will be split. If the value is false, the row will be dropped. Allow me to quote the official documentation (p115 of "iText in Action - Second Edition"):
Ths is a dangerous line, because now not one row will be split. Rows that are too high to fit on a page will be dropped from the table!
I have the feeling that you want all the rows to show up in the table, so I suggest that you change the two lines I mentioned to:
table.SplitLate = true;
table.SplitRows = true;
Actually: why don't you just remove those two lines? The default value of SplitLate and of SplitRows is true.

Same thing happened to me using nested tables.
I solved this problem using .SplitLate = false; in the first table :)

Related

Cant get ExtededDataGrid in Flex to filter with ComboBox on multiple columns

LATEST UPDATE: Issue answered here. Some one else at stackoverflow had a similar issue and it was resolved. Solution provided for convenience. This is the line of code I was missing:
comboHeaderColumn.useLabelFunctionForFilterCompare = true;
that line is followed by these:
comboHeaderColumn.filterComboBoxBuildFromGrid = true;
comboHeaderColumn.labelFunction = formatState;
where formatState is a local method that formats the data for the combobox.
UPDATE: I've now got the combobox's loading with the correct data, but when I select a value nothing happens. The combo boxes load only data that is in the column, and when you select a value in the combobox, it's supposed to filter the rows on that value. It doesn't.
Thanks for looking. I'm having trouble getting multiple filters to work in Flex in Flash Builder 4 using the ExtendedDataGrid and ComboBox's. Here is an image of part of the grid:
The User Name and City filter properly if you type text into the box's above the column header and the Request Date lets you select date ranges if you click on the Custom bar, but the Request Reason and State ComboBoxes do not list anything. I've created them using comboHeaderColumn.filterComboBoxBuildFromGrid = true; but all it does is put "[object Object]" as the only other selection under All.
I've used this article but it will only allow you to use a single filter for the entire grid.
My finished grid will have about 20 columns and from 20,000 to 450,000 rows of data so the filters are really important and I'll need more than one.
The code is very straight forward and loops through all the returned data and if the column is identified as a filter column it does this:
comboHeaderColumn.filterComboBoxDataProvider = codeValuePairs;
comboHeaderColumn.filterComboBoxLabelField = "Value";
comboHeaderColumn.filterControl = "ComboBox";
comboHeaderColumn.filterOperation = FilterExpression.FILTER_OPERATION_TYPE_EQUALS;
comboHeaderColumn.headerText = ac.Header;
comboHeaderColumn.dataField = ac.Name;
if( ac.Header == "State" || ac.Header == "Request Reason" )
{
comboHeaderColumn.filterComboBoxBuildFromGrid = true;
}
ProfileDataColumns.push(comboHeaderColumn);
This creates 2 entries in the combo box: All and [object Object]
What am I missing??? Anyway, after half a day searching I decided to reach out.
Any suggestions or direction to an article would be very much appreciated.
Thanks.

Data formatting in GridView with AutoGenerateColumns true

I've got a GridView in ASP.NET 2.0 with AutoGenerateColumns set to true. It'll be bound at runtime to a DataSet with one of many possible schemas, and I'd rather not set up grids and columns for each possible schema.
Some of the columns in the grid will sometimes be floating point values. It seems the default number formatting turns 0.345 into 0.345000. Is there a way to change the default number format so it trims to a set number of decimals?
You could use strings in your schema instead of floating point for display purposes, and perform the formatting manually, something like this:
EDIT: Without LINQ, you can do the same thing by modifying rows in the schema:
// load source data
DataSet myData = GetDataSet();
// create column for formatted data.
myData.Tables["MyTable"].Columns.Add("AmountFormatted", typeof(string));
// apply formatting
foreach (DataRow dr in myData.Tables["MyTable"].Rows)
dr["AmountFormatted"] = string.Format("{0:0.###}", dr["Amount"]);
// remove source column and replace with formatted column
myData.Tables["MyTable"].Columns.Remove("Amount");
myData.Tables["MyTable"].Columns["AmountFormatted"].ColumnName = "Amount";
C#, LINQ-Based solution:
var theData = GetDataSchema1();
var dataSource = theData.Tables["MyTable"].Select().Select(dr =>
new { /* select only columns you want displayed, and apply formatting */
MyColumn1 = dr["MyColumn1"],
MyColumn2 = dr["MyColumn2"],
MyColumn3 = String.format("#.###", dr["MyColumn3"]),
MyColumn4 = dr["MyColumn4"],
MyColumn5 = dr["MyColumn5"]
}
);
MyGridView1.DataSource = dataSource;
MyGridView1.DataBind()

How to get multiple value from one textbox?

I have created web application and textbox as a textarea. I am using javascript for validation. When I enter value in text box so it should be number not alphabet I have use textmode is multiple line.
My problem is that how I get multiple value from textbox and store in array in javascript and check each value is number or not. I am using the web form. Please help me.
You can get the value from a textarea like
var txtvalue = document.getElementById("txtareaid").value
and if are using a separator then something like
var txtvaluearray = document.getElementById("txtareaid").value.split(';')
will get you all the values in an array if the seperator is ;
Edit
As per your update you can use \n as the separator and as pointed by #Sohnee you can do the validation.
As addition to rahul:
If you want the values in the textarea seperated by line, you can use \r\n as the splitter.
This is a starter for ten.
var textValues = document.getElementById("mytextarea").value.split("\n");
for (var i = 0; i < textValues.length; i++) {
if (isNaN(textValues[i])) {
alert(textValues[i] + " is not a number.";
}
}

Filtering names on the basis of first character of the name

i have a page in which i am displaying the name of all the users i want to filter their names on the basis of first character for that i want to show A B C D ....X Y Z filters on the top on clicking of which it will filter the names accordingly my problem is not the query part but how to add these letters do i have to add 26 link buttons separately or there is some work around for example you might have seen such type of behavior in some music sites for filtering the songs with starting character.
These are few useful links how to do alphabetical paging
1. http://www.highoncoding.com/Articles/209_GridView_Alphabet_Paging.aspx
2. http://aspdotnetcodebook.blogspot.com/2008/03/how-to-add-alphabet-paging-in-gridview.html
Use ASCII characters codes to do this, for example:
var letters = new List<string>()
for(int i = 65; i < 91; i++)
letters.Add(Convert.ToChar(i).ToString());
Display it by adding links to page:
foreach(letter in letters)
{
var hyperlink = new Hyperlink()
{
NavigateUrl = string.Format("Filter.aspx?letter={0}", letter),
Text = letter
}
Page.Controls.Add(hyperlink);
}
Of course instead of Page you can use any other container you want, you just need to add those hyperlinks to controls collection.
Also take care to run this code in proper method, for example by overriding CreateChildControls method.
Regards

Accessing grid columns in same sequence in which they are visible

I need to access columns of infragistics ultragrid in same sequence in which they are being displayed in grid. If i can get the index of column in same sequence as they are visible on grid, i can fix my issues.
Thanks in advance.
Lalit
UltraGridColumn column = this.ultraGrid1.DisplayLayout.Bands[0].Columns[0];
Debug.WriteLine( "Columns in visible order: ");
// Get the first visible column by passing in VisibleRelation.First.
column = column.GetRelatedVisibleColumn( VisibleRelation.First );
while ( null != column )
{
Debug.WriteLine( " " + column.Key );
// Get the next visible column by passing in VisibleRelation.Next.
column = column.GetRelatedVisibleColumn( VisibleRelation.Next );
}
http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v8.2~Infragistics.Win.UltraWinGrid.UltraGridColumn~GetRelatedVisibleColumn.html
I suppose you could try to handle the event that is fired when the order is changed and keep track of all the changes, but this seems like it is asking for subtle bugs to creep in.
I considered looping through all the columns and trying to use some property that would tell me their current position (maybe the TabOrder?) and use that to compile an inorder list of the columns. I guess you might have to loop through each colum using the Column.GetRelatedVisibleColumn() method.
I have not actually implemented it yet as I have other higher priority issues but that may be the road I end up going down.
This is an old question, but I recently had same issue and solved it this way:
var selectedCells = this.Selected.Cells;
List<int> columns = new List<int>();
foreach (var cell in selectedCells)
{
if (!columns.Contains(cell.Column.Index))
columns.Add(cell.Column.Index);
}
columns.Sort((x, y) => this.DisplayLayout.Rows.Band.Columns[x].Header.VisiblePosition.CompareTo(this.DisplayLayout.Rows.Band.Columns[y].Header.VisiblePosition));
You can then use columns to access columns in order they are shown.

Resources