I'm using an ASP repeater on my page, and I want it to create a 3 column grid. In my HTML page, I use a class which sets the third column so that it fits. Basically, the first 2 columns have a margin-right of 28px so it spaces them nicely and then the third class removes the margin-right so that the columns fit.
Problem is, when this comes into the repeater, I can't use the third class and I get a 2 column result. Any ideas on how I can overcome this?
Use a <table>. I know, I know, we aren't supposed to use tables anymore, right? If you are displaying tabular data, you should use a table. If it's a "grid", that sounds like tabular data to me. Is it?
I managed to resolve this without the use of a <table>. It turned out that the <form> didn't have enough width, so I amended this and it worked.
Related
I need to make a table with huge data from a database, I've done it very easy with a gridview in asp.net but there is a big problem,I need to customize that table a lot.
I want something like this, with a row with data about a person and the row after with a description of projects he's in, then another row with another person data and so on.
Table:
https://ibb.co/dJmEqw
And when i click/hover on a platform(platform i want to be a accordion propriety/it can be a button too) to display a table in the right or down side.
Table inside the platform's accordion:
Hope you get the idea guys, how can I do this with horizontal table lines, tables in accordions click/hover and databind? I need to take data from database and put it in the tables I described but I don't know if i can do that with asp.net gridviews which automatically generate the rows/columns it needs or is it another method ?
Any idea, advice, code is welcome, thanks!
A GridView is a simple "PowerPoint" solution for simple data models.
If you want more complex things get rid of the GridView and use a Repeater to create your HTML table instead. The Repeater control lets you create the table row tags in the ItemTemplate. You can easily generate two rows for each item in DataSource.
Of course, you need to generate the table cells (columns) manually as well with the Repeater control. Use Literal or Label controls to view the data in the table cells. Use
<%#: DataBinder.Eval(Container.DataItem, "propertyname") %>
to assign the Text properties of the controls.
I've had a Google but I find no answer. You know how say in MS Word, when you insert a table, you can merge the columns of one single row to create a column-less row? Or have say a main header and then more columns inside it? Like so:
Merged Row:
|Column 1|Column 2|Column 3|
|Value|Value|Value|
|Merged Row|
|Value|Value|Value|
God the text formatting is awful on this web-site...and the Header Column example:
|Main Header||Another Main Header|
|Column 1|Column2||Column1|Column2|
I'm trying to achieve this in a written DataTable in C# which is being populated by an array. But I'm interested in changing its structure as one of the above, whichever is possible/easier.
So I've created my DataTable and added normal columns and rows etc. But I'd like to create either a merged row or a main header to display. Instead of having a repeated value in a single column for the values I am getting.
Can someone please provide a quick example on how I could achieve either one of those? Because repeated value will just look ugly.
Cheers.
You're talking about displaying data in a particular way but a
DataTable has nothing to do with display. It is for storage and that's
that. How you display the data is up to you. The same data can be
displayed in innumerable different ways. In a WinForms app, one of the
most common ways to display the contents of a DataTable is with a
DataGridView. You can choose which columns to display and merge cells
in that grid if desired. In short, you're looking in the wrong place
to do what you want to do. It is a presentation issue, not a data
issue. –
jmcilhinney
I know there is possibility to merge gridview columns but my requirement is some thing different from that I would like to have my gridview as follows
Is it possible to do and also I would like to bind the string values which i will get in a string array.. I would like to create the grid view dynamically and bind the data as per the strings I have is it possible to do.
I had similar situation and ask question few months back. Pivot table help me to solve the issue. check this out.
I have the asp.net application where I am having the editable grid view with the edit,Delete,Add options. this grid having as usual Template fields . I want to hide some columns. I know i can do that by using columns index. but i don't want to follow it. instead I want to hide columns by Id. this is because if in my application further I need to add more columns then there is need to change the code gain and again in the core. so I am choosing this way. Bu as i found <asp:TemplateField /> does not contain Id attribute. so it is become impossible for me to hide <asp:TemplateField/> by Id. any remedy for this ?
You can always do it using column header text. Run a loop through columns of the grid view and compare header text of the column with the constant declared and hide the column, this way, if you are adding any number of columns before or after the column will not affect the code.
Maybe create a div with an id inside a template field and hide that div with client code.
Perhaps just have a different grid markup for each "view" you want to show to the user, so one grid with all the columns, and another with limited columns.
I am assuming you would always be binding the same data to the grid (regardless of whether you are hiding/showing columns), so then you would just need some logic in your code to determine what "view" you want to show the user (i.e. what grid you want to bind to).
Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of a very large system, so it really wouldn't be wise for me to revise the table structure (the app is filled with similar tables).
This is a webapp in C# .NET - data comes in from a webservice and is displayed onscreen in a table. The table's rows are generated with asp:Repeaters, so that the rows alternate colers nicely. The table previously held one item of data per row. Now, essentially, the table has sub-headers... The first row is the date, the second row shows a line of data, and all the next rows are data rows until data of a new date comes in, in which case there will be another sub-header row.
At first I thought I could cheat a little and do this pretty easily to keep the current repeater structure- I just need to feed some cells the empty string so that no data appears in them. Now, however, we're considering one of those +/- collapsers next to each date, so that they can collapse all the data. My mind immediately went to hiding rows when a button is pressed... but I don't know how to hide rows from the code behind unless the row has a unique id, and I'm not sure if you can do that with repeaters.
I hope I've expressed the problem well. I'm sure I'll find a way TBH but I just saw this site on slashdot and thought I'd give it a whirl :)
When you build the row in the databinding event, you can add in a unique identifier using say the id of the data field or something else that you use to make it unique.
Then you could use a client side method to expand collapse if you want to fill it with data in the beginning, toggling the style.display setting in Javascript for the table row element.
just wrap the contents of the item template in an asp:Panel, then you have you have a unique id. Then throw in some jquery for some spice ;)
edit: just noticed that you are using a table. put the id on the row. then toggle it.