Remove top border of GridViewRow in c# - c#

I am adding row controls in rowcreated event of gridview and top border line needs to be removed.
GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell HeaderCell = new TableCell();
HeaderCell.Text = strTotalRecords;
HeaderCell.HorizontalAlign = HorizontalAlign.Left;
HeaderCell.BorderStyle = BorderStyle.None;
HeaderGridRow.Cells.Add(HeaderCell);
HeaderGridRow.BackColor = Color.White;
gvGrid.Controls[0].Controls.AddAt(totalRowIndex, HeaderGridRow);
I am using the below code to remove border and it doesn't work.
HeaderCell.Attributes.CssStyle.Add("border-top", "none");
HeaderCell.Attributes.CssStyle.Add("border-top-style", "none");
HeaderGridRow.Attributes.CssStyle.Add("border-top", "none");
HeaderGridRow.Attributes.CssStyle.Add("border-top-style", "none");
Please suggest me how this can be handled.

add a css class to your grid and add style to that css class like below.
.gridview
{
border-top:none !important;
}

Related

ASP.NET Webforms Gridview Footer

In ASP.NET webforms, is there a way to configure the FooterTemplate of the GridView to allow for overflow in the footer, but to also retain the above columns width like below? As it is now, any footer overflow also stretches the cells above it.
You can do it using gridview_rowcreated() event.
Just in the event allow rowspan and column with desired column and row
Modify it with your requirement.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
GridView FooterGrid = (GridView)sender;
GridViewRow FooterRow = new GridViewRow(0, 0, DataControlRowType.Footer, DataControlRowState.Insert);
TableCell Cell_Footer = new TableCell();
Cell_Footer.Text =""; // As per your requirement
Cell_Footer.HorizontalAlign = HorizontalAlign.Center;
Cell_Footer.ColumnSpan = 2;
HeaderRow.Cells.Add(Cell_Footer);
Cell_Footer = new TableCell();
Cell_Footer.Text = ""; // As per your requirement
Cell_Footer.HorizontalAlign = HorizontalAlign.Center;
Cell_Footer.ColumnSpan = 1;
Cell_Footer.RowSpan = 2;
FooterRow.Cells.Add(Cell_Footer);
Cell_Footer = new TableCell();
Cell_Footer.Text = ""; // as per your requiremnt
Cell_Footer.HorizontalAlign = HorizontalAlign.Center;
Cell_Footer.ColumnSpan = 3;
FooterRow.Cells.Add(Cell_Footer);
GridView1.Controls[0].Controls.AddAt(0, FooterRow);
}
}
If want more explanation go through the link
http://codedisplay.com/merge-merging-or-split-spliting-gridview-header-row-or-columns-in-asp-net-c-vb-net/

Dynamically added cells disappear while exporting to Excel

I have a gridview. I have created two columns dynamically in the Row_DataBound event of the gridview.
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCell cell1 = new TableCell();
cell1.Width = 100;
e.Row.Cells.Add(cell1);
TableCell cell2 = new TableCell();
cell2.Width = 100;
e.Row.Cells.Add(cell2);
}
else
{
TableCell cell1 = new TableCell();
cell1.Width = 100;
cell1.Text = "<span style='font-weight:bold'>Total Punches";
e.Row.Cells.Add(cell1);
TableCell cell2 = new TableCell();
cell2.Width = 110;
cell2.Text = "<span style='font-weight:bold'>Hours Worked";
e.Row.Cells.Add(cell2);
}
I want to export the whole grid to Excel sheet. When I click the Export button, the last two columns which I created on Row_DataBound disappear in the excel sheet.
Can anyone help me solving this.
Thanks in Advance.
Try to move the logic to RowCreated event.

Read Gridview exact rows after adding a dynamically added header?

I am adding a table header row dynamically as shown below. It is rendered correctly.
So now I have 2 headers.
protected void gvCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridViewRow newHeaderRow = new GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
TableCell cell1 = new TableHeaderCell();
cell1.ColumnSpan = 1; //e.Row.Cells.Count;
cell1.Text = "Expected";
TableCell cell2 = new TableCell();
cell2.ColumnSpan = 2;
cell2.Text = "One";
TableCell cell3 = new TableCell();
cell3.ColumnSpan = 2;
cell3.Text = "Two";
TableCell cell4 = new TableCell();
cell4.ColumnSpan = 2;
cell4.Text = "Three";
newHeaderRow.Cells.Add(cell1);
newHeaderRow.Cells.Add(cell2);
newHeaderRow.Cells.Add(cell3);
newHeaderRow.Cells.Add(cell4);
((GridView)sender).Controls[0].Controls.AddAt(0, newHeaderRow);
}
}
If my gridview is having 3 rows, and loop through gridview it will read only 2 row.
It is skiping the last row.
Any thoughts
I solved this. write this code on RowCreated event.
I wrote this code on RowDataBound so created header row was not consistent.
protected void gvCustomers_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridViewRow newHeaderRow = new GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
TableCell cell1 = new TableHeaderCell();
cell1.ColumnSpan = 1; //e.Row.Cells.Count;
cell1.Text = "Expected";
TableCell cell2 = new TableCell();
cell2.ColumnSpan = 2;
cell2.Text = "One";
TableCell cell3 = new TableCell();
cell3.ColumnSpan = 2;
cell3.Text = "Two";
TableCell cell4 = new TableCell();
cell4.ColumnSpan = 2;
cell4.Text = "Three";
newHeaderRow.Cells.Add(cell1);
newHeaderRow.Cells.Add(cell2);
newHeaderRow.Cells.Add(cell3);
newHeaderRow.Cells.Add(cell4);
((GridView)sender).Controls[0].Controls.AddAt(0, newHeaderRow);
}

Read Gridview header value of a dynamically added header

I am adding a table header row dynamically as shown below. It is rendered correctly. Now I need to read the first cell value of the newly added header row in a button click event. How can we read the header value?
I cannot use gvCustomers.Rows since it will not take header row.
I cannot use gvCustomers.HeaderRow.Cells[0].Text; also since there are two header rows
CODE
protected void gvCustomers_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridViewRow newHeaderRow = new GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
TableCell cell1 = new TableHeaderCell();
cell1.ColumnSpan = 1; //e.Row.Cells.Count;
cell1.Text = "Expected";
TableCell cell2 = new TableCell();
cell2.ColumnSpan = 2;
cell2.Text = "One";
TableCell cell3 = new TableCell();
cell3.ColumnSpan = 2;
cell3.Text = "Two";
TableCell cell4 = new TableCell();
cell4.ColumnSpan = 2;
cell4.Text = "Three";
newHeaderRow.Cells.Add(cell1);
newHeaderRow.Cells.Add(cell2);
newHeaderRow.Cells.Add(cell3);
newHeaderRow.Cells.Add(cell4);
((GridView)sender).Controls[0].Controls.AddAt(0, newHeaderRow);
}
}
protected void Btn_Click(object sender, EventArgs args)
{
}
I am using the following approach. Any improvement suggestions?
int current = 0;
int headerCount = grdTransactions.HeaderRow.Cells.Count;
for (current = 0; current < headerCount; current++)
{
TableHeaderCell cell = new TableHeaderCell();
cell.Text = grdTransactions.HeaderRow.Cells[current].Text;
originalHeaderRow.Cells.Add(cell);
}

WPF Flow Document Layout

I'm trying to print a WPF FlowDocument. The layout needs to be in the form of 4 documents per page, laid out as follows:
Doc1 | Doc2
-------------
Doc3 | Doc4
(Sorry, I couldn't come up with a better way of illustrating the layout).
The page needs to fill, so if Doc1 & 2 are blank or just one or two characters, it still needs to print them the same size as Doc3 & 4.
The code I'm using is as follows (sorry it's long, I've tried to abridge where feasible):
PrintDialog printDialog = new PrintDialog();
if ((bool)printDialog.ShowDialog().GetValueOrDefault())
{
FlowDocument flowDocument = new FlowDocument();
flowDocument.PageHeight = printDialog.PrintableAreaHeight;
flowDocument.PageWidth = printDialog.PrintableAreaWidth;
flowDocument.PagePadding = new Thickness(25);
flowDocument.ColumnGap = 0;
flowDocument.ColumnWidth = (flowDocument.PageWidth -
flowDocument.ColumnGap -
flowDocument.PagePadding.Left -
flowDocument.PagePadding.Right);
Table myTable = new Table();
myTable.BorderThickness = new Thickness(3);
AddCols(myTable); // Add 2 cols
TableRowGroup rg = new TableRowGroup();
TableRow row = new TableRow();
AddRows(myTable); // Adds 2 rows
TableCell cell = new TableCell(new Paragraph(new Run("Doc1")));
cell.BorderThickness = new Thickness(1);
cell.BorderBrush = Brushes.Black;
// Repeat 4 times
row.Cells.Add(cell);
myTable.RowGroups.Add(rg);
doc.Blocks.Add(myTable);
....
The problem that I have is that although this does print, it doesn't try to fit it to the page as described above. Is what I am attempting possible and if so, how?
EDIT:
From looking here I believe what I actually need is a way to calculate the height of the paragraph, so that I can set the Padding property. Unfortunately the solution proposed in this link doesn't work!
Try placing the entire block in a grid so as to give it the uniform layout and then place the grid in the block and block inside your single table cell. See if this works for you -
Grid grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition());
grid.RowDefinitions.Add(new RowDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition());
Label text1 = new Label();
text1.Content = "Doc1";
grid.Children.Add(text1);
Grid.SetColumn(text1, 0);
Grid.SetRow(text1, 0);
Label text2 = new Label();
text1.Content = "Doc2";
grid.Children.Add(text2);
Grid.SetColumn(text2, 1);
Grid.SetRow(text2, 0);
Label text3 = new Label();
text1.Content = "Doc3";
grid.Children.Add(text3);
Grid.SetColumn(text3, 0);
Grid.SetRow(text3, 1);
Label text4 = new Label();
text1.Content = "Doc4";
grid.Children.Add(text4);
Grid.SetColumn(text4, 1);
Grid.SetRow(text4, 1);
BlockUIContainer block = new BlockUIContainer(grid);
Table table = new Table();
TableRowGroup rg = new TableRowGroup();
TableCell cell = new TableCell();
cell.Blocks.Add(block);
TableRow row = new TableRow();
row.Cells.Add(cell);
rg.Rows.Add(row);
table.RowGroups.Add(rg);
doc.Blocks.Add(table);
You could create your own custom DocumentPaginator. See here:
http://www.codeproject.com/Articles/164033/WPF-Visual-Print-Component
http://www.codeproject.com/Articles/31834/FlowDocument-pagination-with-repeating-page-header
http://www.switchonthecode.com/tutorials/wpf-printing-part-2-pagination
http://www.codeproject.com/Articles/138233/Custom-Data-Grid-Document-Paginator
Is this what you're looking for?
Convert xaml flow document to xps
question, you added the cell to the row.cell and the rowgroup to the table, but did you add the row to the rowgroup?

Categories