ASP:Repeater - when all else fails. I use the repeater control more
than any other databound control because you get loads of scope for
mucking around with the format of your HTML.
<asp:repeater runat="server">
<HeaderTemplate>
<h2>Employment History</h2>
<div id="employmentHistory">
</HeaderTemplate>
<ItemTemplate>
<table>
...
</table>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
Israel Richner wrote:
I think maybe I was too vague in my description. Here is what I'll be
doing, I wrote this site using ASP.NET 2.0
www.svtn.com. If you
navigate to the employment page you'll see an online application for
drivers to apply online.
It was secured using SSL but it's not now. Long story.
Anyway, currently when a driver fills out the application and fills in
all required fields the data is inserted into 2 tables.
tbl_Applications
tbl_EmploymentHistory
Once that happens the "Confirmation" page loads querying for the data
and creating a crystal report which looks like an employment
application. The crystal report is loaded into a crystal report viewer
on the page.
Once the driver reviews the information and clicks submit a second
time, a pdf file gets created and then attached to an email and sent to
HR
I no longer want the website creating the pdf files, for security and
maintenance reasons, I wrote a windows service which queries the table
looking for new applications. This windows service handles creating the
pdf and emails it to HR. I only want the website saving the data once
it's confirmed to be accurate.
So to replace the "Confirmation" page crystal report viewer, I need to
display the data so that it looks like an employment application.
I don't know how much employment history is filled out, could be 2 or 3
or 4.
I don't think a datagrid will work here because the date won't be
displayed horizontally, it will look more like this.
Comany Name: Start Date:
Address: End Date:
City: State: Zip:
This format will repeat over and over again for each prior employer.
I do have some books, I plan to get my MCSD eventually. Just need to
find time to read them.
How would you guys accomplish this task?
sloan wrote:
Izzy,
Its bad mojo to bring asp thinking to DotNet.
At least I think that is what you're doing. I'm not sure, but
hopefully this
can help.
Here is some help:
If you want to use dynamic columns for your datasource, then you
should
dynamically create your DataGrid.
Do a google search for
datagrid "new BoundColumn"
Here is some code I pulled from a hit (using that google search)
public void TestHyperLinkColumn()
{
// First add a simple bound column
BoundColumn nameColumn = new BoundColumn();
nameColumn.DataField = "ProductName";
nameColumn.DataFormatString = "{0}";
nameColumn.HeaderText = "Product";
// Now add the HyperLink column
HyperLinkColumn linkColumn = new HyperLinkColumn();
linkColumn.DataTextField = "ProductName";
linkColumn.DataTextFormatString = "{0} Details";
linkColumn.DataNavigateUrlField = "ProductID";
linkColumn.DataNavigateUrlFormatString =
"/MyApp/ProductDetails.aspx={0}";
linkColumn.HeaderText = "Details";
// Add the link in a BoundColumn
// where the text can be the same for all rows
BoundColumn blinkColumn = new BoundColumn();
blinkColumn.DataField = "ProductID";
blinkColumn.DataFormatString =
"<a href='/MyApp/ProductDetails.aspx={0}'>Details</a>";
blinkColumn.HeaderText = "Details";
DataGrid1.Columns.Add(nameColumn);
DataGrid1.Columns.Add(linkColumn);
DataGrid1.Columns.Add(blinkColumn);
DataGrid1.AutoGenerateColumns = false;
DataTable dt = GetNorthwindProductTable();
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
}
NOW.. if you want the datagrid to show up at a specific place, then
just
DRAG one onto the aspx page.
Assume (from above) that DataGrid1 has already been dragged onto your
form.
I have to build the table dynamically because the number of records
are
unknown. So I won't know how many controls I need until the reader
is
finished.
How would I accomplish this?
Thanks for the reply!
Izzy
Jesse Liberty wrote:
First, while you can do what you are suggesting, you typically
would
place
an asp control into the table cell, and then you would write your
data
to
the text field or to an another appropriate property of that
control.
For
example, you might write
"<table><tr><td><asp:label id="mylabel"
runat="server"></td></tr></table>"
then in your code you can write
mylabel.Text = myTable.Row[0]["NameColumn"];
but all of this is assuming quite a bit about asp.net controls
and
adolnet
controls and quite a bit more. I strongly recommend that you find
a book
that takes you through asp.net in a bit more orderly fashion so
that it
doesn't all seem like such a muddle.
There are quite a few out there (I happen to like the O'Reilly
book
Programming ASP.NET 2nd Edition, but I know the author). Go to a
good
book
store and read through a couple; it will be time and money well
spent.
Find
one that meets your style and needs and that tells the story step
by
step
but that focuses on the issues you care about.
Best of luck.
-j
--
Jesse Liberty
Microsoft MVP
Author/ Programmer
http://www.LibertyAssociates.com
How do I write information to a specific location on a web page
from
the code behind page?
For instance I have 2 controls on my web form, in the code
behind page
I query a database and read the results with a data reader.
While
reading the records I format it into an html string like
"<table><tr><td>[inserted reader data]</td></tr></table>"
I know I can use Response.Write(string) but how do I control
where
that
new table gets written too? I want it placed between the two
controls
on the form.
What am I missing?
Izzy