How do you do this? Simple ASP.NET GridView question

J

Johnny Jörgensen

I do a lot of winforms programming in C# and VB.NET, but not I've been asked
to do an ASP.NET application, and that's a first for me. So I hope you will
bear with this basic question, because I'm really puzzled.

I've got an SQL Server 2005 DB, and for the sake of simplification, we can
say that I've got two tables, tblBooks and tblAuthors. tblBooks contains an
integer column called iAuthorID, and tblAuthors contain an integer field
called iAuthorID and a string field called strAuthorName. The two iAuthorID
fields are of course linked through foreign/primary key relationship.

I want to bind an editable gridview to tblBooks and let the user see and
change the data. So I've got a datasource set to tblBooks, and the contents
of the table is shown. the iAuthorID column shows the integer value of the
iAuthorID field. However, I would of course like to show the Authors NAME
instead - collected from tblAuthors.

I've converted the iAuthorID column to a template field, and by exchanging
the EditItemTemplate Textbox with a ComboBox, I can databind the column to
the ID and Name fields in tblAuthors.

But how do I show the author name when the gridview is NOT in Edit mode? I
cannot - as far as I can tell - use the Label control in the templatefields
ItemTemplate for that. The label text can only be bound to the iAuthorID
field in tblBooks (which it should be), but this value cannot be used to get
the value from another tables fields? I cannot use the formatting options
for this, I guess?

I don't like webforms - everything is much simpler in winforms... :-(

But I would really appreciate it if somebody could tell me the solution to
this problem, because I've exhausted all my ideas....

Cheers,
Johnny J.
 
M

Mr. Arnold

Johnny Jörgensen said:
I don't like webforms - everything is much simpler in winforms... :-(

But I would really appreciate it if somebody could tell me the solution to
this problem, because I've exhausted all my ideas....

You should post to a donet.Webform or dontnet.ASP NG, which is part of
msnews.microsoft.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

Top