DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Dataview & Relationships

  1. #1
    Join Date
    Apr 2005
    Posts
    17

    Dataview & Relationships

    Hi,

    How do i input 2 related tables' fields into a dataview which
    is displayed on a datagrid, choosing the fields (columns)
    i want to display, anyone knows or have any examples?


    Table1:
    ID, Name, Age, Sex, Job

    Table2:
    ID, JobName, Salary

    For example, I created a relationship "Table1Table2" I would like
    my datagrid to display the fields: ID,Name,Age,Sex,Job,JobName.
    JobName is from Table2, the others from Table1.
    Not sure how to do it, these are my codes so far

    daTable1.Fill(ds)
    daTable2.Fill(ds)

    dataview = ds.DefaultView

    datagrid.Datasource = dataview

    -
    help appreciated! thanx!

  2. #2
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    There is nothing wrong in what you have done, Infact with existing code you get your solution changing properties. If the grid has AutoGenerateColumns property set = true , change it to false.. Then in the Property Builder add Bound Columns and set properties for the columns you only want.

    So this way you choose what you want to display and dont allow the grid to decide. Have a look at the HTML on the aspx page , you could earn more and probably achieve more with a grid...

    This should work fine

    If you want to take the approach of playing the dataview .. I dont see why you should do it..

  3. #3
    Join Date
    Apr 2005
    Posts
    17
    how do i set it? examples?

  4. #4
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    select the grid
    press F4 under behaviour you should have AutogenerateColumns property change it to false

    Now on the same property window you will see two hyperlinks at the bottom Auto Format & Property Builder

    Click on Property Builder and select Columns on the menu on the left tab
    You have a check box on the top of this form uncheck it (Create columns automaticallyt at run time)
    Now on the list of AvailableColumns choose Bound Column and click on the button > this places a bound column in the ShowColumns list and properties of this bound column appear editable at bottom of these lists
    Set a Header Text, Footer Text, Sort Expression for sorting and in the DataField property give the column name in the DataView for example your columns Title should be set in this property

    Well for the columns from both tables if you are getting it from the database in the stored procedure use an inner join by far the most efficent use. Creating DataRelations and using them is useful in a Master-Child relation not a join scenario like urs where you want to fdo a inner join and get the columns from both data Tables

    then your ds.Tables[0].defaultview will work

    For a master detail here is the code below,
    ds.Table[0] = "Table1";
    ds.Table[1] = "Table2";
    DataRelation dr = new DataRelation("Table1Table2", dt1.Columns"ID"],dt2.Columns["ID"],false);
    ds.Relations.Add(dr);
    DataView dv = ds.Tables[0].Rows[0].GetChildRows(dr);
    grid.DataSource = dv;
    grid.DataBind()
    Will get back on Nested as of now use an inner join and get the data from the stored procedure by far the most efficient for data
    Last edited by srinivas_s; 05-20-2005 at 01:49 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center