Blank row, every other row in data grid

Hmmm, here's a tricky one...  How can I programatically add a blank datagrid row, every other row, to a bound data grid?  Here's what I want to accomplish...  I want the odd rows to be a master record, and then the even rows to contain another datagrid with details.  I've seen all the posts and how-tos about nesting data grids, but quite honestly, it looks like crapp and it wastes screen real estate.  My plan is to colspan the even rows so that the data grid fits nicely in there.  Any ideas?

Thanks,
Rob Richard

www.robrichard.com
0
robrichard
8/22/2003 1:17:57 PM
asp.net.presentation-controls 72751 articles. 1 followers. Follow

9 Replies
181 Views

Similar Articles

[PageSpeed] 19

Do you require sorting and paging?  If not, you could use the DataList, and put an html table in each row.  Something like this


<asp:DataList id="dl1" runat="server" . . .>
<HeaderTemplate>
<table>
<tr>
<td>column1</td>
<td>column2</td>
. . .
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,"column1")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"column2")%></td>
. . .
</tr>
<tr>
<td><asp:Textbox id="txt1" runat="server" /></td>
<td><asp:Textbox id="txt2" runat="server" /></td>
. . .
</tr>
</table>
</ItemTemplate>
</asp:DataList>

The hard part is making sure the header table width matches the item table width. Hope this helps.

Darren
0
daccardo
8/22/2003 2:20:19 PM
Thanks Darren.  Unfortunately, I do need to have paging and sorting, and thus the need for the datagrid.  I would have done it with a server side table and just manually populate the cells with the data, but then I'd have to manually page and sort, and that just really defeats the purpose.

Any other ideas out there?
Rob Richard

www.robrichard.com
0
robrichard
8/22/2003 2:27:55 PM
Other suggestion:

Why not have a datagrid with a singel column in which you build your own layout by using a table.
I know it's a bit more work for building the column template but as shuch you have full control of the layout for each line.
The population of the child datagrid you can handle in DataGrid_DataItemBound().
Don't forget to name all the controls with a proper name so they are easy accessible in your code.

website, application, database, design?

---------------------------------------------

architect , developer, service provider



http://www.opmaat.be
0
opmaat
8/22/2003 3:37:24 PM
By George, I think that'll work!  Sometimes it's the easy solutions that are overlooked!!!
Rob Richard

www.robrichard.com
0
robrichard
8/22/2003 3:53:49 PM
Actually, now that I've sat down to do this, it's not a very great solution.  It totally hoses up my column sorting...  Any other ideas out there?


Rob Richard

www.robrichard.com
0
robrichard
8/23/2003 1:04:27 AM
Okay, I think I'm on to something here...  I added this code in the ItemCreated event for the data grid.  Only problem is is that it puts my "detail" row BEFORE my "master" row - can't figure out how to put each row AFTER my "master" row.


public void dgGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
{
System.Web.UI.WebControls.DataGridItem dgRow = new DataGridItem(e.Item.ItemIndex+1, 1, ListItemType.Item);
System.Web.UI.WebControls.TableCell dgCell1 = new TableCell();
System.Web.UI.WebControls.TableCell dgCell2 = new TableCell();
dgCell1.Text="Row # " + e.Item.ItemIndex.ToString();
dgCell2.ColumnSpan=5;
dgCell2.Text="COOL!";

dgRow.Cells.Add(dgCell1);
dgRow.Cells.Add(dgCell2);
dgFiles.Controls[0].Controls.AddAt(e.Item.ItemIndex, dgRow);
}
}
}


Rob Richard

www.robrichard.com
0
robrichard
8/23/2003 2:58:18 AM
Wouldn't you know it - no sooner did I post that last message and I found the key.  For all ye in search of the same knowledge, here's how I solved it...  

In the ItemDataBound event of the datagrid, I add the following code:

if (e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
System.Web.UI.WebControls.DataGridItem dgRow = new DataGridItem(e.Item.ItemIndex+1, 1, ListItemType.Item);
System.Web.UI.WebControls.TableCell dgCell1 = new TableCell();
System.Web.UI.WebControls.TableCell dgCell2 = new TableCell();
dgCell1.Text="Row # " + e.Item.ItemIndex.ToString();
dgCell2.ColumnSpan=5;
dgCell2.Text="COOL!";

dgRow.Cells.Add(dgCell1);
dgRow.Cells.Add(dgCell2);
dgFiles.Controls[0].Controls.Add(dgRow);
}


(Also note that I posted the incorrect code in the previous post. It should have actually been the code block above, just in the ItemCreated event - sorry for any confusion)...
Problemo SOLVED!!!!

Rob Richard

www.robrichard.com
0
robrichard
8/23/2003 3:04:08 AM
Could make a drawing of what you would like to have on the datagrid?

just 1 row + 1 detail row
website, application, database, design?

---------------------------------------------

architect , developer, service provider



http://www.opmaat.be
0
opmaat
8/23/2003 3:18:12 AM
I've totally hosed this post and have started a new one, it can be found at http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=317887
Rob Richard

www.robrichard.com
0
robrichard
8/24/2003 1:06:08 AM
Reply:

Similar Artilces:

How do I "row-wrap" ? i.e., have 2 rows of headers, and 2 rows in grid for each data record?
Hi I have built a view in Sql Server, and built my Sql Data Source, and everything looks good... I have my data grid populating nicely. But, I want the headers and rows to wrap - not inside each cell, but to fit the page. Let's say I have 10 columns, and only 5 will fit in the width of a webpage.  I would want the headers to wrap, so there are two rows of headers, then each data record would fill 2 rows in the grid. Example:  <headers> Last Name................First Name.............. Middle Name.............DOB............SSN............. <end of this row in grid>...

add a new blank row to the end of the data (edit / data grid)
Hi, I am using the template for the edit/data grid and am trying to replace my database fields with the sample provided. Everything is okay until I try adding a new record. My database has two fields. First is a small int of size 2 and the second field is a var char. When it gets to this piece of code I am not sure how to proceed and the program fails. ' add a new blank row to the end of the data Dim rowValues As Object() = {"", ""} It says system format exception : input string was not in the correct format at system number pa...

adding a blank header row /row above the header row
is it possible to add a blank row above the header row in gridview for adding some links and buttons the links will respond to thae data in the grid and the buttons are for login / regisration etc....  if yes how it can be done or how do i achieve it. Its better that u create a table with a single row with columns matching the GridView columns. Set the table width same as the GridView width. This will make the GridView Look as if there is a row above its header.Please do not forget to click Mark As Answer on the post that helped you. Regards,Iam Srikanth Reddy....

Multiple grid rows per Data row in GridView
I have a dataset that is binded to a gridview. The dataset has 5 fields and a description. I want to display 1 row for the 5 short fields and 1 row underneath it for the description. (per record)   For example: ID Name  Surname Field3 Field 4 1   John     Smith      blah    blah     This is the long description for  John Smith spanning 5 cells 2   Peter    Parker     blah    blah     This is t...

ADO.net problem: i can not view image data for the rest of my table rows except the image for the first row but i can read all the other non image fields for all rows.
Hi i have a table with the following fields imgid............int imgdata........image imgtitle.........varchar(max) imgType........varchar(max) imgLength.....bigint incident_id.....int i have no problem with uploading the image but viewing the uploaded image(s) in a gridview has caused me great pain. The probelm is i have two pages. page1 grabs the image to display and page2 has a gridview that displays the grabed image. I wanted to have an sql statement like SELECT * FROM mytable WHERE incident_id=someValue. IF i have 5 records in this table and i view page2 ...

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

On selecting a row from a grid view
Hi I'm hoping someone can help me out. I've got a simple grid view where I've enabled the 'select' option. When the user clicks select, I would like a row of data to be written to the database. For now I'm hard codeing the data written, but once I've got it working I'd like to pass some of the values from the line selected - one step at a time! The code I've put togeather from various google searches doesn't through any errors - but it also doesn't add any values to the DB. Any thoughts???? Thanks in advance. Imports System.Data.SqlClient Impo...

Data Control in a row for a grid view
Pardon me if this is a very basic question. I come from the windows world am new to .net. I have a grid view and will be showing a label in a row cell. I am dynamically creating this label. When I am doing that I am looping in the dataset and dynamically creating the label and adding it to the row cell. I am creating a label component and the id is label1.When I am looping through the dataset the same label is being created with the same id. and I am able to attch it to the datacell.My program works but hers my concern/question..in a windows app world if I was creating the same control ...

How to control Hieght of Data Grid Rows
Hi All Can I have rows in a data grid that are of different height? I know it is possible but who this is the question??? Yes, it can be controlled but .... cannot be enforced. For example, adding this: <ItemStyle Height="30px"></ItemStyle> to the columns declaration will try to make the row height to be 30px but ... if contents of any cell of the row do not fit - row height will be extended. Also, there is always a minimum height you can use, it depends on the cell contents (can be fully controled up to 1px level only if contents of the cell are images onl...

Retaining Data Grid row position when "editing" row?
In ASP 2.0 is it possible to retain the cursor position on the Datagrid row after the "edit" is selected, so users do not need to scroll back to the line ? I am using editable datagrid for updating the records which are in SQL table.If I click on edit link of the record,is it possible to show the editable row on top of the page or top of the datagrid.Or Is it possible to focus the page on that editable row?For I am clicking on 1000th row of datagrid for editing, I need to scroll through the page to discover the record I clicked for editing.It is very much annoying to scroll through when lar...

Data Controls insert rows into gridview then insert rows from gridview into SQL Table
Hello there, I'm still new at performing miracles with code . Currently I am having trouble with my latest coding adventure I have a web application which records jobs and labour assigned to jobs. The issue in particular I'm having is the way in which labour is to be assigned. I want to use standard controls (Textbox, Dropdownlist) to record the values into a gridview (ie,put multiple rows into the gridview using the controls). Then, when all the inserting is complete, the user clicks a submit button to insert all the rows from the gridview into a database table. The reason for...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Arranging data on multiple rows into a sigle row (converting rows into columns)
Hello, I have a survey (30 questions) application in a SQL server db. The application uses several relational tables. The results are arranged so that each answer is on a seperate row: user1   answer1user1   answer2user1   answer3user2   answer1user2   answer2user2   answer3 For statistical analysis I need to transfer the results to an Excel spreadsheet (for later use in SPSS). In the spreadsheet I need the results to appear so that each user will be on a single row with all of that user's answers on...

How to append a blank data row in Grid View on runtime
My query is:I have a grid view control on my web page where i am using objectdatasource to display records of a property in which i have a varchar field of BedroomRequired having data ("0", "1", "2", "3", "4", "5"). I want to display records with group on bedrooms value like if value is "1" then append a blank data row where i could put a heading "1 bedroom" and then print the 1 bedrooms records and 2, 3, 4 and 5 bedrooms data respectively. How can i append a blank data row ? please help me Go to this we...

Web resources about - Blank row, every other row in data grid - asp.net.presentation-controls

File:World Map Blank.svg - Wikipedia, the free encyclopedia
I, the copyright holder of this work, release this work into the public domain . This applies worldwide. This file contains additional information, ...

Barbie Blank (@TheBarbieBlank) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here Barbie Blank @ TheBarbieBlank ...

What Job Burnout Feels Like - Steve Blank
If you hang around technology companies long enough, you or someone you know may experience “burnout” – a state of emotional exhaustion, doubt ...

Point Blank Adventures - Aim & Shoot on the App Store on iTunes
Get Point Blank Adventures - Aim & Shoot on the App Store. See screenshots and ratings, and read customer reviews.

One of the other screens at LEX had a blank Windows message that needed some attention. - Flickr - Photo ...
Explore rick's photos on Flickr. rick has uploaded 15630 photos to Flickr.

Passport-free travel is a blank cheque for government intrusion
The convenience of travelling without a passports comes at a price: how much personal data we will be willing to give up and to whom.

Taylor Swift’s misheard lyrics have fans drawing a ’blank space’ - The Courier-Mail Search Search
EVEN the most devout Taylor Swift fans can get a lyric wrong, with Swift’s mum admitting she had been singing the wrong words to hit song Blank ...

Before & After: A "Blank Canvas" Office Gets a Hip New Look
... to Cowork.rs Gowanus a couple of months ago. The coworking space just opened, and I was inspired by the potential of a new space and 'blank ...

RED ALERT: Paul Ryan Set to Hand Obama a Blank Check to Bring In an "Unlimited Number" of Islamic Refugees ...
... Senators Sen. Richard Shelby (R-AL) and Sen. Jeff Sessions (R-AL) that Rep. Paul Ryan (R-WI) is preparing to issue President Obama a blank check ...

Saturday's hockey roundup (Dec. 19): St. John's Prep blanks Hingham
Saturday's hockey roundup (Dec. 19): St. John's Prep blanks Hingham Boston Herald Dimitri Dutkewych, Danny Angell and Jacob Montepeluso scored ...

Resources last updated: 12/22/2015 12:02:26 PM