I am trying to print contents of grid view control. But I want to skip few columns from printing. Print functionality is working fine, but how to skip few columns of grid view from printing.
Below is my code:
PrintHelper.PrintWebControl(grdAppointments );
grdAppointments is name of grid view control. It prints all columns of grid, but I want to print only few columns.
When printing the page-
1) First hide the unwanted columns
2) Then call the print() function
3) Show previously hided columns
You can refer following link to hide the columns
Hide GridView column using javascript
A non-programmatical solution could be that you create a temporary grid and copy all selected columns/items to it, and print that gridview data. Then dispose it.
To get selected columns:
if (dataGridView1.SelectedColumns.Count > 0)
{
foreach (DataGridViewColumn c in dataGridView1.SelectedColumns)
dataGridView2.Columns.Add(c);
}
Related
I am currently working on a website using ASP.Net and C# on Visual Studio 2012.
I have a GridView that displays data on Page_Load from my database and a button that should add new row AT THE FIRST ROW of my GridView .
Is there a way on doing this? I tried adding rows with textboxes dynamically but I can't retrieve the input data from it because it disappears on PostBacks.
Ideas so far:
Start populating the gridview from 2nd row to make the first row
clear and add control to it from the client side but I dont know how
to do it and if it is even possible.
Place the textboxes on the HeaderRow, then hide HeaderRow on Page_Load, then display the HeaderRow on button click. But the labels of the column will disappear because it will be replaced with TextBoxes.
I was working with grid-view,I try to enter some text on cell 1 on 0th row
it automatically increment other rows and I again try to write some on cell 2 on the same 0th row ,Simultaneously increments other rows.
So for I tried with
dataGridView1.AllowUserToAddRows=true;
It doesn't allow me to write inside a gridview, I think click rows has to generate automatically.
Please resolve this logic based on Cell Value Changed events.
It is not a good practice to add rows to your gridview. If you want to add something to your view, add them to the data that you are binding to it, and then bind. Very easy.
So you have something like this:
List<MyType> data = ReadDataFromSomewhere();
data.Add(new MyType(){StringItem="Something", IntItem =0});//Adding your row
data.Insert(1,new MyType(){StringItem="Other Thing", IntItem =1});//Inserting to position 1
gv.DataSource = data;
gv.DataBind();
I don't know think I wrote any code for this since the properties are all default. I don't want the user to have to add those by themselves when it is in the middle of the run.
It lets me add in columns but not rows in the designer.
Is there any property that can start the program with more than 1 row in the data grid view?
Populating the grid with data must be done with code. If you populate the grid in the Load event handler then the user will see that data when the form is displayed. You can add data directly to the grid or you can populate a DataTable or some other list and bind that to the grid.
If you're saying that you actually want multiple blank rows in the grid then you need to add those rows. The row you see by default is not actually part of the data of the grid. It's just there to indicate to the user that they can enter data.
I wanted to ask some questions regarding some requirements. My client want that when he clicks on a Button, a form should be displayed asking the user to add the number of rows and columns.After adding those a matirx/gridview should be displayed according to the size that the user has entered.
The main problem is that I have used a TableLayoutPanel and its not changing the size of the rows and columns.
public void set(int rows, int columns)
{
this.SuspendLayout();
tableLayoutPanel1.RowCount = rows;
tableLayoutPanel1.ColumnCount = columns;
tableLayoutPanel1.Controls.Add(new ComboBox());
//tableLayoutPanel1.Controls.Add( NewRackControl() rack());
this.ResumeLayout();
//this.Refresh();
}
What will be best to add a GridView or a TableLayoutPanel?
How can I change the number of rows and columns.
Thirdly if a user enter text to any of the position of that gridview how I will be able to take the position of that paticular row or column and then save it into the Database ?
Instead of using TableLayoutPanel please use DataGridView
the Selected Rows from different popped form can be passed between 2 forms and update can be done to the working Grid-view.
The changes required (like Sizes, Color, Icons ,Highlighting, etc)
can be Done in Gridview.
You can change the no of rows & columns dynamically by changing properties(visibility & items) of it.
yes, you can save the changes made in view back to database and this is one of famus features provided by updateble event.
Please use DataGridView this is best for your Problem.
I have been given a mockup that I do not know is possible to code in ASP.NET without being a real html and javascript wizard.
I want a GridView that when a row is selected, the selected row expands and below the selected row a panel of additional information is shown, which would also include another small GridView. The idea is this would all be in-line. So if the user selected row 4, then the additional information would appear below row 4 and then after the additional information the parent GridView would continue with row 5.
Ultimately I would want to do a multi-select type of set up, but first I need to figure out if this is even possible. Also, the solution must be 508 Compliant
The one solution I considered was using only one "column". Then I would put all my fields in the ItemTemplate, and my detail panel content in the EditItemTemplate and instead of selecting the row, set it to edit mode. The problem with this solution is I lose the functionality of multiple columns if I throw everything in one huge ItemTemplate.
Any and all suggestions or ideas are appreciated.
What you're describing would be best fulfilled with a ListView control. It takes a little more templating work to set up than a grid view, but you have much more control over it and you can emulate the look of a GridView. You would set your Selected Item template to contain another ListView (or GridView) thats bound to your detailed data.
I've done this using a gridview inside a ListView and using ajaxcontroltoolkit collapsible panel
Your parent list would be a listview that would have 2 table rows for each item, on the first row your parent column, on the second row use colspan and add a gridview wrapped on a collapsible panel