Images not showing in table with dynamically created HyperLink - c#

I'm dynamically creating a HyperLink with an image, and it being entered into every cell from a dataset.
Well for some reason, the images are not showing up in any of the cells, the link is there but the image is not and I have no idea why.
When I stepped through the code, the ImageUrl is correct, and when I copy the path and paste in explorer the image shows up, but its not showing up in the cells.
The code is...
for (cellCtr = 1; cellCtr <= 3; cellCtr++)
{
HyperLink link = new HyperLink();
// Create a new cell and add it to the row.
TableCell tCell = new TableCell();
/* If the rowcounter is equal to the record numbers
* then it has to break because if not it will throw an error
* saying that there is no row at ending position */
if (rowCtr == rN)
break;
string subjectid = myDs.Tables[0].Rows[rowCtr]["SubjectID"].ToString();
string iconUrl = myDs.Tables[0].Rows[rowCtr]["IconUrl"].ToString();
link.ID = subjectid;
link.ImageUrl = iconUrl;
link.NavigateUrl = "~/WebForm2.aspx";
tCell.Controls.Add(link);
tRow.Cells.Add(tCell);
rowCtr++;
/* If the cellcount is 3 then it needs to break, if not then
* you'll miss every 4rth record, don't know why. But this works */
if (cellCtr == 3)
{
rowCtr = rowCtr - 1;
break;
}
}
I'm at a loss for why the images won't appear...
Thanks

Related

Print data of one column of data gridview in print document in C#?

int height = 300;
int i = 0;
while (i < PurchaseDepartDataGridView.Rows.Count)
{
height += PurchaseDepartDataGridView.Rows[0].Height;
e.Graphics.DrawString(PurchaseDepartDataGridView.Rows[i].Cells[0].FormattedValue.ToString(),PurchaseDepartDataGridView.Font,Brushes.Black, new Rectangle(25,height,PurchaseDepartDataGridView.Columns[0].Width,PurchaseDepartDataGridView.Rows[i].Height));
i++;
}
This code does not work properly.
I want only to print the values of only one column of datagridview.

How to make a Static and Dynamic Button in Dynamic datagridview

Hi I'm getting the wrong inputs with my datagridview. (see below picture)
I want it exactly to be like the picture below
So here is my database as you can see below
and here is my Code. So my code generates button and if i click it. It should generate the proper values in the datagridview.
object[] itemDetail;
object[] itemLi = itemsWS.searchItem("", "drinks", "all");
int x = 35;
int cleft = 0;
for (int i = 0; i < itemLi.Length; i++)
{
itemDetail = itemsWS.getItemInfo(itemLi[i].ToString());
Button myButton = new Button();
myButton.Tag = i;
myButton.Click += (senders, args) =>
{
var button = senders as Button;
selectedItenOutputOrderTabGrid.ColumnCount = 4;
selectedItenOutputOrderTabGrid.Columns[0].Name = "Item Code";
//selectedItenOutputOrderTabGrid.Columns[1].Name = "description SCRAP";
selectedItenOutputOrderTabGrid.Columns[1].Name = "Each";
selectedItenOutputOrderTabGrid.Columns[2].Name = "Quantity";
selectedItenOutputOrderTabGrid.Columns[3].Name = "Amount";
//this.selectedItenOutputOrderTabGrid.Columns[1].Visible = false;
string row1 = itemsWS.getItemInfo(itemLi[(int)button.Tag].ToString()).ToString();
numericPopUp numPopUp = new numericPopUp();
numPopUp.Show();
selectedItenOutputOrderTabGrid.Rows.Add(itemsWS.getItemInfo(itemLi[(int)button.Tag].ToString()));
};
myButton.Text = itemDetail[1].ToString() + "\n " + itemDetail[2].ToString();
myButton.Top = cleft * 180;
myButton.Left = 70;
myButton.Location = new Point(x, cleft);
myButton.Size = new Size(100, 60);
drinksOrderManagementTab.Controls.Add(myButton);
x += 135;
if (x >= 537)
{
x = 35;
cleft += 80;
}
}
Please any help would be appreciated. Thank you very much
Essentially your row is doing just what you told it to do: it shows the given items. Your problem is, that these items come straight out of the database and include every column - without restrictions or reordering. That's why you see the column order reflected in your row (first item_code, then description and so on).
Easiest way here is to construct a new array including only the data you actually want to show in your row. Something like (pseudo-code):
object[] dbOutput = itemsWS.getItemInfo(itemLi[(int)button.Tag].ToString());
object[] items = new object[] {
dbOutput[1], //description
dbOutput[2] //sale_price
//and so on
};
selectedItenOutputOrderTabGrid.Rows.Add(items);
I'm quite sure there are advanced techniques and personally I would lay this off to when you select the data from the database, but this should solve your problem.

Split Gridview values into other column having same header, if row count value exceeds some limit?

I am getting data from SQL DB and displaying those data in Gridview in asp webpage, now I want to spilt those data into other columns based on row values.
For Ex: I have two columns like Employee Id, Employee Name if row values exceeds 100, I want to display remaining data into other columns with same header.
Here, same header means data is coming from same table, I have requirement like I want to display to other column if row value exceeds 100 count.
Why not add another Grid view next to the existing one, which will contain the same columns... plus It's not clear what you mean by 'row values' I based my answer on Row Count exceeds 100.
If what you need is a way to span between 2 columns, it requires lot of work:
https://social.msdn.microsoft.com/Forums/windows/en-US/87004d70-482a-4b86-ba18-371670254b6a/how-to-merge-headers-in-a-datagridview
Concerning the split of the values to 2 columns, following an idea (it will not work in case the second column is >100, it requires some adjustements)
private void button2_Click(object sender, EventArgs e)
{
const int limitRows = 100;
var col1 = new DataGridViewTextBoxColumn();
var col2 = new DataGridViewTextBoxColumn();
var col3 = new DataGridViewTextBoxColumn();
gridProduct.AutoGenerateColumns = false;
gridProduct.RowHeadersVisible = false;
gridProduct.ColumnHeadersVisible = true;
gridProduct.Columns.Add(col1);
gridProduct.Columns.Add(col2);
gridProduct.Columns.Add(col3);
var colIndex = 0;
int rowIndex = 0;
for (int i = 0; i <= 200; i++)
{
if (i == limitRows)
{
colIndex = 1;
rowIndex = 0;
}
else if (i > limitRows)
rowIndex++;
else
rowIndex = gridProduct.Rows.Add();
gridProduct.Rows[rowIndex].Cells[colIndex].Value = string.Format("Val for row {0}", i);
gridProduct.Rows[rowIndex].Cells[2].Value = string.Format("Another val for row {0}", i);
}
}

Table in Word document with n columns to fit as per page size and allow truncated columns to break across page using Aspose.words for .Net

I'm generating a word document using Aspose.Words(Evaluation mode) for .Net in which I'm building a table as following
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.StartTable();
for (int i = 0; i < 5; i++)
{
for(int j = 0; j < 20; j++)
{
builder.InsertCell();
builder.Write("Column : "+ j.toString());
}
builder.EndRow();
}
builder.EndTable();
doc.Save(ms, Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Doc));
FileStream file = new FileStream(#"c:\NewDoc.doc", FileMode.Create, FileAccess.Write);
ms.WriteTo(file);
file.Close();
ms.Close();
Now this code gives following word file with invisible columns, it should give 20 columns
.
Is there any way to break invisible columns to next page?
Rows can go to next page, not columns, it is the behavior of Microsoft Word. You can change the design and formatting of the document to make all columns visible. Below are few pointers.
Reduce the page margins (left and right)
Make the cells width fixed. This way, the text inside each cell will break downwards, if more characters found.
Change orientation to landscape, you will have a wider page.
Check the related articles and code sample on Aspose.Words documentation website.
Try the updated code sample below:
string dst = dataDir + "table.doc";
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set margins
doc.FirstSection.PageSetup.LeftMargin = 10;
//doc.FirstSection.PageSetup.TopMargin = 0;
doc.FirstSection.PageSetup.RightMargin = 10;
//doc.FirstSection.PageSetup.BottomMargin = 0;
// Set oriantation
doc.FirstSection.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;
Aspose.Words.Tables.Table table = builder.StartTable();
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 20; j++)
{
builder.InsertCell();
// Fixed width
builder.CellFormat.Width = ConvertUtil.InchToPoint(0.5);
builder.Write("Column : " + j);
}
builder.EndRow();
}
builder.EndTable();
// Set table auto fit behavior to fixed width columns
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
doc.Save(dst, Aspose.Words.Saving.SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Doc));
I work with Aspose as a Developer Evangelist.

ABCPDF Calculation of header size and position.

The problem is a header file, which I have to include on each page of the pdf file generated by abcpdf.
The header file contains more than one image file and several lines of text, which varies from case to case.
The problem is that I do not know how to calculate the size of the header. I need to have its size to allocate the rectangle positions to put the rest of html file on each page together with header. I am using C#.
First off you need to create your document with enough space at the top to allow a header to be added. The settings below are for a normal A4 document with a header of about 1/5 of the page. Remember the coordinates on a PDF are from the bottom right not the top left..
//Setting to create the document using ABCPdf 8
var theDoc = new Doc();
theDoc.MediaBox.String = "A4";
theDoc.HtmlOptions.PageCacheEnabled = false;
theDoc.HtmlOptions.ImageQuality = 101;
theDoc.Rect.Width = 719;
theDoc.Rect.Height = 590;
theDoc.Rect.Position(2, 70);
theDoc.HtmlOptions.Engine = EngineType.Gecko;
The code below out puts a header across each page on the document, with a header image then a colored box under the image with some custom text in.
The header image in this case is 1710 x 381 to keep the resolution of the image as high as possible to stop it looking fuzzy when printed.
private static Doc AddHeader(Doc theDoc)
{
int theCount = theDoc.PageCount;
int i = 0;
//Image header
for (i = 1; i <= theCount; i++)
{
theDoc.Rect.Width = 590;
theDoc.Rect.Height = 140;
theDoc.Rect.Position(0, 706);
theDoc.PageNumber = i;
string imagefilePath = HttpContext.Current.Server.MapPath("/images/pdf/pdf-header.png");
Bitmap myBmp = (Bitmap)Bitmap.FromFile(imagefilePath);
theDoc.AddImage(myBmp);
}
//Blue header box
for (i = 2; i <= theCount; i++)
{
theDoc.Rect.String = "20 15 590 50";
theDoc.Rect.Position(13, 672);
System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#468DCB");
theDoc.Color.Color = c;
theDoc.PageNumber = i;
theDoc.FillRect();
}
//Blue header text
for (i = 2; i <= theCount; i++)
{
theDoc.Rect.String = "20 15 586 50";
theDoc.Rect.Position(25, 660);
System.Drawing.Color cText = System.Drawing.ColorTranslator.FromHtml("#ffffff");
theDoc.Color.Color = cText;
string theFont = "Century Gothic";
theDoc.Font = theDoc.AddFont(theFont);
theDoc.FontSize = 14;
theDoc.PageNumber = i;
theDoc.AddText("Your Text Here");
}
return theDoc;
}

Categories