Search:
Namespaces
Discussions
.NET v1.1
Feedback
DataTable question
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngdatagridrepeaterdatalist' list
.
Bob Herrmann
-- Moved from [aspngfreeforall] to [aspngdatagridrepeaterdatalist] by Terri Morton <
Click here to reveal e-mail address
> --
I have a strange problem that I was hoping someone could help me with. I want to read one record from a SQL table and then display the headings and values vertically down a page, preferrably in a datagrid. So instead of:
CustID CustName City
123 Bob Miami
I want to display:
CustID 123
CustName Bob
City Miami
I also want this dynamic so if columns are added/deleted from the table then all existing columns will display. So far I have created a datatable with one row for each column in my SQL customer table. So in the above example, I read in one customer record from my SQL table and then write 3 records to datatable. I then bind this table to my datagrid and I get this in my datagrid:
123
Bob
Miami
So far so good but I would like to also have the column name like I showed above. How can I get the column name from SQL table as a column in my datatable? Like I said, I need for this to be dynamic so I don't want to hardcode this.
Thanks,
Bob
Reply to this message...
Doug J. Nelson
Hey Bob,
The solution to your problem is to use a DataRepeater. Like follows
<table>
<asp:Repeater id=3DmyRepeater runat=3Dserver ...blah blah blah>
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(
Container
.DataItem, "ColumnName")%></td>
<td><%#DataBinder.Eval(
Container
.DataItem, "Value") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
A datagrid is essentially a more stylized repeater. Repeaters give you
complete control over how anything is rendered and still allows for very
cool dynamics.
Hope this helps.
Doug Nelson
SynApp north
305 Arch St
Cloquet, MN 55720
(218) 878 - 2015=20
(218) 878 - 2019 fax
Reply to this message...
KHALLERAN@hklaw.com
public System.Data.
DataSet
GoDoReShape(System.Data.
DataSet
InTable)
{
System.Data.
DataSet
OutTable=new System.Data.
DataSet
();
OutTable.Tables.Add();
OutTable.Tables[0].Columns.Add("Label");
OutTable.Tables[0].Columns.Add("Value");
int i=0;
foreach(System.Data.
DataColumn
CounterCol in
InTable.Tables[0].Columns)
{
if(!(InTable.Tables[0].Rows[0].ItemArray[i].ToString().Equals("")))
{
string []
MyArray={CounterCol.ColumnName.ToString(),InTable.Tables[0].Rows[0].ItemArra
y[i].ToString()};
OutTable.Tables[0].Rows.Add(MyArray);
}
i++;
}
return OutTable;
}
Kevin A. Halleran
-----Original Message-----
From: Bob Herrmann [mailto:
Click here to reveal e-mail address
]
Sent: Tuesday, August 13, 2002 4:10 PM
To: aspngDataGridRepeaterDatalist
Subject: [aspngdatagridrepeaterdatalist]
DataTable
question
-- Moved from [aspngfreeforall] to [aspngdatagridrepeaterdatalist] by Terri
Morton <
Click here to reveal e-mail address
> --
I have a strange problem that I was hoping someone could help me with. I
want to read one record from a SQL table and then display the headings and
values vertically down a page, preferrably in a datagrid. So instead of:
CustID CustName City
123 Bob Miami
I want to display:
CustID 123
CustName Bob
City Miami
I also want this dynamic so if columns are added/deleted from the table then
all existing columns will display. So far I have created a datatable with
one row for each column in my SQL customer table. So in the above example,
I read in one customer record from my SQL table and then write 3 records to
datatable. I then bind this table to my datagrid and I get this in my
datagrid:
123
Bob
Miami
So far so good but I would like to also have the column name like I showed
above. How can I get the column name from SQL table as a column in my
datatable? Like I said, I need for this to be dynamic so I don't want to
hardcode this.
Thanks,
Bob
| [aspngdatagridrepeaterdatalist] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.aspfriends.com/aspfriends/aspngdatagridrepeaterdatalist.asp
=
JOIN/QUIT
Reply to this message...
Tim Musschoot
A repeater would be a good solution. However, if you realy want to use
the
DataGrid
, you should place a '<br>' between the values so they
appear on different lines. This method is not very reliable when the
with of the columns is smaller than needed for the data (spanning over
multiple lines will occur automatically and will mess up your manual
separation with <br> tags)
Tim Musschoot
Software Engineer
AspFriends Moderation Team
Click here to reveal e-mail address
http://www.aspalliance.com/timmusschoot
-----Oorspronkelijk bericht-----
Van: Bob Herrmann [mailto:
Click here to reveal e-mail address
]
Verzonden: dinsdag 13 augustus 2002 22:10
Aan: aspngDataGridRepeaterDatalist
Onderwerp: [aspngdatagridrepeaterdatalist]
DataTable
question
-- Moved from [aspngfreeforall] to [aspngdatagridrepeaterdatalist] by
Terri Morton <
Click here to reveal e-mail address
> --
I have a strange problem that I was hoping someone could help me with.
I want to read one record from a SQL table and then display the headings
and values vertically down a page, preferrably in a datagrid. So
instead of:
CustID CustName City
123 Bob Miami
I want to display:
CustID 123
CustName Bob
City Miami
I also want this dynamic so if columns are added/deleted from the table
then all existing columns will display. So far I have created a
datatable with one row for each column in my SQL customer table. So in
the above example, I read in one customer record from my SQL table and
then write 3 records to datatable. I then bind this table to my
datagrid and I get this in my datagrid:
123
Bob
Miami
So far so good but I would like to also have the column name like I
showed above. How can I get the column name from SQL table as a column
in my datatable? Like I said, I need for this to be dynamic so I don't
want to hardcode this.
Thanks,
Bob
| [aspngdatagridrepeaterdatalist] member
Click here to reveal e-mail address
= YOUR
| ID
|
http://www.aspfriends.com/aspfriends/aspngdatagridrepeaterdatalist.asp
| = JOIN/QUIT
Reply to this message...
System.ComponentModel.Container
System.Data.DataColumn
System.Data.DataSet
System.Data.DataTable
System.Web.UI.DataBinder
System.Web.UI.WebControls.DataGrid
System.Windows.Forms.DataGrid
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com