best approach to use

J

J

I'm a bit new to asp.net and I'm investigating the best approach to this:

I have a contact table that includes stuff like Name, address, phone, etc.
Because each contact can contain multiple 'product' values, I have a
separate product table that has a many-to-one relationship with the contact
table. I also have an 'industry' table that also has a many-to-one
relationship with the contact table.

1. I would like to have a page that has a search box, and displays results
with summary info.

2. By clicking one of the records in the summary results, another page that
contains the contact edit screen comes up. This will include an 'product'
section and an 'industry' section which has check boxes to select all the
products or industries for this particular contact (looking up the values in
lookup tables).

Ideally, I could leverage asp.net controls as much as possible but sometimes
I seem to beat myself up trying go get them to do what I want them to do. I
can very quickly and easily do step number 1 by using a databound GridView
control. Yet it's not intuitive to my how to make the last name a link to
an edit page. Accomplishing number 2 seems to fall apart with the
many-to-one relationship data.

Any ideas on how to approach this would be appreciated.
 
Y

younlaot

A real quick answer to one of your questions. How do you set the last
name to a link that will go to an edit page...

First, declare the OnDataBound property for the gridview. Then in the
code behind, in the OnDataBound function, check for the incoming data
to be an actual row of data and not a header or footer. Then when
inside that block, use the eventarg to set the column that holds the
last name as a link to a seperate page that processes the editing.

Here is some sample code:

IN THE ASPX FILE:

<asp:GridView ID="GridView1" runat="server"
OnDataBound="GridView1_RowDataBound">
</asp:GridView>

IN THE CODE BEHIND:

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
// Make sure we are processing a DataRow
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Get last name, 0 is the first cell (column) in the
gridview, if you wanted a different cell, enter a different number
string lastName = e.Row.Cells[0].Text;

// Change last name to a link to edit page
e.Row.Cells[0].Text = "<a href='edit.aspx?lastName="+
lastName + "</a>";
}
}

Of course, going off of this, you could pull the users id and pass
that to the edit page in case there are multiple last names. You
would just add that inside the RowDataBound function.

Then in the edit page, you will have to do some processing to get the
one-to-many relationship to work, but it's definately do-able!

Have fun!
 
P

Peter Bromberg [C# MVP]

It sounds to me that you want to have associative or "junction" tables.

CONTACT CONTACT_PRODUCT PRODUCT
========= ============= =======
CONTACT_ID CONTACT_ID PRODUCT_ID
PRODUCT_ID

The Contact_product table will have multiple entries for the same contact,
each one "pointing" to a product ID for that contact_ID in the PRODUCT table.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top