DataGrid Problem

Discussion in 'ASP.NET / ASP.NET Core' started by brightmosquito, Dec 24, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I want to display data using DataGrid from database.

    Database tables:
    Table -- Cities
    ID Name
    1 Los Angeles
    2 Chicago

    Table -- Customers
    ID CityIDName
    1 1John Belly
    2 2Becky Smith

    I want to display customer's info using DataGrid. How can I show city's name instead of its ID?
     
  2. One way is to map the ItemDataBound event and walk through the Cells and check the ID, if it has 'id' in the name then mark the cell not visible. That's the idea anyway it's not ver batim. The cells can be obtained in that event from the second argument to the event method IIRC.

    You can also buy a 3rd party control that has good DataGrid support and it should be more convenient and easier. Just make sure that if you ever want to run on Mono on Linux that the vendor's control runs there too.

    Here is a very good site to help: www.datagridgirl.com.
    /emoticons/burger.gif
     
  3. why use the itemdatabound event if you can obtain the desired result with straight sql ?


    get your data by joining the tables:


    select cities.name as CityName,customers.name as CustomerNamefromcustomersinner join Cities on cities.ID = customers.cityID.





    --
    Steurm
    www.steurm.net/steurm
    [​IMG]
     
  4. Got it. Thank you so much
     
  5. >> why use the itemdatabound event if you can obtain the desired result with straight sql ?

    Yes you can use a join but what if the user wants to edit the data? What if name isn't part of the primary key or a unique index? Now you would have to have the original id So my answer, while requiring more technical diligence provides the most flexibility for architectural design changes.
     
  6. >> why use the itemdatabound event if you can obtain the desired result with straight sql ?

    Also I said, 'One way is to map the ItemDataBound event', I didn't say it was the only way, the best way, etc.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page