|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Hello,
I have a Datareader with 2 fields from the database in it. I would like to use the DataGrid to display them. This I can do. If the DataReader has 4 rows in it I would like to display the records in 2 DataGrid rows. So I would have the following: ColHeader1 ColHeader2 ColHeader1 ColHeader2 Field1(0) Field2(0) Field1(1) Field2(1) Field1(2) Field2(2) Field1(3) Field2(3) Is this possible with the DataGrid? If so could you please point me in the right direction? I have tried everything I can think of. Thanks With a datagrid.... very difficult
It's easier with a repeater Example (VB) <ASP:REPEATER Runat=server DataSource="<%# DummyData %>"> <HEADERTEMPLATE><TABLE> <TR><TH>Even</TH><TH>Even</TH><TH>Odd</TH><TH>Odd</TH></TR> </HEADERTEMPLATE> <ITEMTEMPLATE> <TR><TD><%# DataBinder.Eval(Container.Dataitem, "Caption" ) %></TD> <TD><%# DataBinder.Eval(Container.Dataitem, "Caption" ) %></TD> <%# IIF( Container.ItemIndex = CTYPE(Container.Parent, System.Web.UI.WebControls.Repeater).DataSource.Rows.Count - 1, "</TR>", "") %> </ITEMTEMPLATE> <ALTERNATINGITEMTEMPLATE> <TD><%# DataBinder.Eval(Container.Dataitem, "Caption" ) %></TD> <TD><%# DataBinder.Eval(Container.Dataitem, "Caption" ) %></TD> </TR> </ALTERNATINGITEMTEMPLATE> <FOOTERTEMPLATE> <TR><TH>Even</TH><TH>Even</TH><TH>Odd</TH><TH>Odd</TH></TR> </TABLE> </FOOTERTEMPLATE> </ASP:REPEATER> Where my DummyData is a datatable with one "Caption" Column Clever, eh? NOTE: the IIF is to properly terminate the <TR> in case you have an odd number of members in your datasource. the original HTML specs state that <TR>s don't have to be terminated, so you don't *have* to use it if you are not serving HTML 4 / XHTML Hope this helps -- addup -- I didn't notice the datareader in your original post
a (slightly) better way of doing this would be <ITEMTEMPLATE> <TR><TD><%# DataBinder.Eval(Container.Dataitem, "Caption" ) %></TD> <TD><%# DataBinder.Eval(Container.Dataitem, "Caption" ) %></TD> </ITEMTEMPLATE> and <FOOTERTEMPLATE> <%# IIF( CTYPE(Container.Parent, System.Web.UI.WebControls.Repeater).Items.Count Mod 2, "</TR>", "") %> <TR><TH>Even</TH><TH>Even</TH><TH>Odd</TH><TH>Odd</TH></TR> </TABLE> </FOOTERTEMPLATE> Thank you for your quick reply. Looks like it is going to work. I will
try it and get back to you. Thanks again and happy holidays.
Master Pages and Cross-Page Form Information
Listbox is overlapping the Textbox in Asp.net Basic formatting for HTML text in ASP.NET 1.1 ? Hi Is there a way to set onmouseover for a LinkButton in ASP.NET 2.0 ? Setting Hyperlink URL in Gridview Broswer Compatibility timer functionality Localize control file upload control - ASP2.0 |
|||||||||||||||||||||||