Click here to Skip to main content
15,885,197 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a table contains name, age, dob, mobileno, landphoneno, officeno, fax.

I want to display the name, age, dob and any of the contact Nos from mobileno, phoneno, officeno, fax Nos that was given by the user.

If the user had not given the mobileno but given the phoneno then the phoneno is diplayed in gridview as cotactno heading.The precedency is landphoneno,mobileno and officeno

Thanks in Advance!
Posted

There are various ways to do this,

you just fetch only that number that are present in DB
else

fetch all the columns from DB and there is an event called Rowdatabound. In this you can check what data is present and take the decision according, I mean show or hide accordingly
 
Share this answer
 
you can use the following code in a procedure, get the result and bind it to your gridview
SQL
select Name,Age, DOB, "Contact No"=
    CASE
        WHEN landphone IS NOT NULL THEN (SELECT landphone from customer cst where cst.CustID = outCust.CustID)
        WHEN mobilephone IS NOT NULL THEN (SELECT mobilephone from customer cst where cst.CustID = outCust.CustID)
        WHEN officeno IS NOT NULL THEN (SELECT officeno from customer cst where cst.CustID = outCust.CustID)
        WHEN fax IS NOT NULL THEN ( SELECT fax from customer cst where cst.CustID = outCust.CustID)
        ELSE 'no contact no'
    END
FROM Customer outCust


I've used a table something like your table definition (only the difference is I've one Primary Key CustID)
 
Share this answer
 
v3
Comments
senguptaamlan 13-Dec-10 8:23am    
if this approach solves your need ... please mark it as answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900