Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to populate a field in gridview with data FROM ANOTHER TABLE?

Reply
Thread Tools

How to populate a field in gridview with data FROM ANOTHER TABLE?

 
 
Kurt of San Jose
Guest
Posts: n/a
 
      04-04-2008
All-

Please advise as to what's the best way to display data in a column in a
grid view (and I'm using a dataset) in a table (say TABLE2) which:

- is non-zero only if a boolian field in the same row is true, and
- when the boolean field is true, gets its value FROM ANOTHER TABLE?

Say we have these two tables:
TABLE1
table1_id (int)
some_number (int)

TABLE2
table2_id (int)
table1_id (int, FK)
is_coming (bit)

Now, I display TABLE2 in a gridview and add, say, a calculated column named
"value". So again, I'd like the logic for the calculated field to be as
follows:

- If is_coming = False, then dispaly "0" or nothing
- If is_coming = True, then display the corresponding some_number value from
TABLE1.

So what I think I need is some type of conditional select statement. The
last message from someone on a forum suggested using this select statement in
a stored procedure:

1 SELECT
2
3 table2.table2_id,
4 table2.is_coming,
5 CASE table2.is_coming WHEN 'False' THEN '0' ELSE table1.some_number
END AS 'MyArtificialColumn'
6
7 FROM table2
8
9 INNER JOIN table1
10 ON table2.table1_id = table1.table1_id

However, I'm not sure how to display the value returned by the SP in the
gridview column. Note, too, that I'd want the ability to sum the column in
the gridview footer (but I think I can handle that).

Searching the internet, I've only been able to find out that Expressions in
calculated fields can only use values from the same table (no lookups in
other tables). Another suggested that the value of the field could be
populated by using INSERT or UPDATE trigger on table2. Not sure how to
proceed. Any ideas would be appreciated.

Thanks!

-Kurt


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
Populate Hidden field on post back and retrieve value from Hidden Field Rick ASP .Net 3 04-13-2010 05:38 PM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM
Populate a popup window with clickable records from an Access DB and upon clicking, populate a selectbox on the original webpage with the clicked record Enjoy Life ASP General 2 02-23-2005 10:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57