Can I use a DataGrid for this ?

Last post 05-08-2008 6:36 AM by GianniP. 4 replies.

Sort Posts:

  • Can I use a DataGrid for this ?

    05-01-2008, 8:52 AM
    • Loading...
    • GianniP
    • Joined on 08-06-2006, 3:42 PM
    • Posts 71

    Hi

     

    If I have one table with a country list and another table with say countryid + province, I would like to display the info in the following manner.

     

    ---------------------------------------------------------------
    Countryname
    ----------------------------------------------------------------
                                      ProvinceName
                                      ProvinceName
                                      ProvinceName
                                      ProvinceName
    ---------------------------------------------------------------
    Countryname
    ----------------------------------------------------------------
                                      ProvinceName
                                      ProvinceName
                                      ProvinceName
                                      ProvinceName
    -----------------------------------------------------------------

     

    etc etc. Curently, the DataGride I am using shows the following:

    ---------------------------------------------------------------
    Countryname              ProvinceName
    Countryname              ProvinceName
    ---------------------------------------------------------------

    so for example

    ---------------------------------------------------------------
    Ireland              Leinster
    Ireland              Munster
    Italy                 Marche
    Italy                 Pugli
    -----------------------------------------------------------------

    Basically I don;t want to duplicate the country name.

    Any suggestions ?

     

    Thanks

    GP

  • Re: Can I use a DataGrid for this ?

    05-01-2008, 9:23 AM
    Answer
    • Loading...
    • claytonc
    • Joined on 04-23-2008, 1:43 PM
    • Posts 29

    Hi,

    Here is something similar that you are trying to do...

    http://www.codeproject.com/KB/webforms/MasterDetail.aspx?fid=254259&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=1684450 

    Clayton
    If this post answered your question please 'Mark as Answer'
  • Re: Can I use a DataGrid for this ?

    05-01-2008, 9:25 AM
    Answer
    • Loading...
    • jagdipa
    • Joined on 06-26-2003, 7:00 AM
    • Manchester, UK
    • Posts 1,731
    Cannot give you the code, but I can tell you how to accomplish this. Note that this only works if you are using a dataset (but try it anyway).

    1. First change the country column from a bound column to a template column.

    2. In the country template column, put a label control, with an id of lblCountry.

    3. In your code-behind, declare a global string variable called vDatagridPreviousCountry.

    4. In your code-behind, create a function that handles the datagrids itemdatabind function. i.e.
    Dim my function (...) handles mydatagrid.onItemDataBind
    The easiest method of doing this is using the visual studio drop down lists (just above the code section) to select the datagrid first, and then the event second.

    5. In this function, write some code that is similar to the following:
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    Dim DRV As DataRowView = e.Item.DataItem
    If Not vDatagridPreviousCountry = DRV("myDBCountryColumnName") Then
    Dim lblCountry as Label = e.Item.FindControl("lblCountry")
    lblCountry.text = DRV("myDBCountryColumnName")
    vDatagridPreviousCountry = DRV("myDBCountryColumnName")
    End If
    End IF
    Intelligence is a burden.
    Jagdip Singh Ajimal
    Manchester (and yes, I am a Manchester United fan)
  • Re: Can I use a DataGrid for this ?

    05-01-2008, 11:31 AM
    Answer
    • Loading...
    • claytonc
    • Joined on 04-23-2008, 1:43 PM
    • Posts 29

    Hi,

    Just found an article by luck that might interest you...

    http://www.progtalk.com/ViewArticle.aspx?ArticleID=54 

    Clayton
    If this post answered your question please 'Mark as Answer'
  • Re: Can I use a DataGrid for this ?

    05-08-2008, 6:36 AM
    • Loading...
    • GianniP
    • Joined on 08-06-2006, 3:42 PM
    • Posts 71

    I think the above were all very advanced for me.

    I just wanted to make sure that when I have multiple itesm linked to one category, that the categorey name is no repeated over and over as it is no necessary.

     

    so instead of having

    Dog Poodle  

    Dog Labrador

    Dog Daschund

     

    I will have

    Dog

         Poodle

         Labrador

         Daschund

    Cat

         x

         y

         z

Page 1 of 1 (5 items)