How do I create a completely programmed list/table?

  • Thread starter Thread starter manwslohand
  • Start date Start date
M

manwslohand

Newbie here. Stupid question follows. Please be kind.

I'm using c#.net 2003 and have a web form that uses a datagrid to
display a list from a table. It's working okay but I want to expand the
features of the data being displayed. I've tried the datagrid and data
repeater but I can't customize it to the level I want. I need to be
able to, depending on the data in the table, turn on/off certain
graphics on each line and would selectively display pictures, if one is
available for a record.

I can't see how to do this (reasonably) within the standard controls.
Is there a way to bind a control to a function? I'm thinking to write
out the HTML code manually from within the function (response.write)
and have it display on the form. I need the control to be able to
grow/expand to accomodate lots of records. Don't want the user to have
to scroll within the control.

Any suggestions or code examples on how to do this? Many thanks in
advance.
 
I'm not positive, but I would figure that you would want to use a
DataGrid control in ASP.NET. I believe that you can set a template for the
items, and for each column. For values you don't want to see, set the value
of the column in your data set to null, and have the template process it
accordingly.

Hope this helps.
 
As a follow-up to Nick's response, you will find that you can do all kinds of
custom formatting in the DataGrid's ItemDataBound handler. This fires for
every row in the source as it is databound to the grid, and gives you an
opportunity to gain access to the individual column values in the source as
well as controls in the cells of the grid to do whatever custom formatting
suits your fancy.
Peter
 
This is gonna seem a lot like writing Classic ASP code in C#.

Add a placeholder control to your page, where you want the table.
At the point where you have all the data you need for the table, create
an HtmlTable class.
using System.Web.UI.HtmlControls;
// :
HtmlTable table = new HtmlTable();
This will give you an <TABLE></TABLE> when the html is rendered. So,
naturally, the next step is to create the <TR> & <TD>s:
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell td = new HtmlTableCell();

td.InnerText = "Hello,";
tr.Controls.Add(td);

td = new HtmlTableCell();
td.InnerHtml = "<B>World!</B>";
tr.Controls.Add(td);

table.Controls.Add(tr);

At this point, we have
"<table><tr><td>Hello,</td><td><b>World!</b></td></tr></table>"

Repeat the last few steps until the table is built as you like.

You can also add attributes to the controls:
table.Attrbutes["border"] = "1";

Finally, add the table to the placeholder:
placeholder1.Controls.Add(table);

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
 
I'm not positive, but I would figure that you would want to use a
DataGrid control in ASP.NET. I believe that you can set a template for the
items, and for each column. For values you don't want to see, set the value
of the column in your data set to null, and have the template process it
accordingly.

I'd like to use datagrid, but it doesn't appear to be able to go as far
as I need. Let me try to flesh it out a bit more.

We have the following tables:

Customer (names, addresses)
Ratings
BuddyList

For each customer record displayed, we might have related ratings
records or buddylist records. If the person has ratings records, then I
want to display a graphic that links to another form. Same thing for
buddylist. Any idea on how to do this with datagrid? Basically, I need
to be able to do sub-queries within a given column.

I like the info that James also provided but I've yet to wrap my head
around it fully. Any further input is appreciated.
 
Back
Top