Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how can bind two tables to one grid view

how can bind two tables to one grid view

Scheduled Pinned Locked Moved ASP.NET
csstutorial
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bandanenilima
    wrote on last edited by
    #1

    hello Can anybody tell me how to bind morethan two tables to grid view I want to add items from one table and can add year and month value from another tables

    C N N 3 Replies Last reply
    0
    • B Bandanenilima

      hello Can anybody tell me how to bind morethan two tables to grid view I want to add items from one table and can add year and month value from another tables

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Are you talking about tables in a database or tables in a DataSet? In the database you can join the tables together use SQL to produce a single result set.

      Man who stand on hill with mouth open wait long time for roast duck to drop in

      1 Reply Last reply
      0
      • B Bandanenilima

        hello Can anybody tell me how to bind morethan two tables to grid view I want to add items from one table and can add year and month value from another tables

        N Offline
        N Offline
        Niladri_Biswas
        wrote on last edited by
        #3

        First of all the question itself is not clear. Case I Assuming that it is database table Solution Produce a single resultset by aplying join or any other condition based on your demand Case II Assuming it is DataTable Solution Create a custom datatable table that will have all the fields. Fill the table programatically and then make it as the datasource of your grid view e.g. [ Some rough pseudo code]

        Datatable dt1 = new Datatable();
        dt1.Columns.Add(Col1);
        dt1.Columns.Add(Col2);

        dt1.Rows.Add("Val1","Val2");
        dt1.Rows.Add("Val3","Val4");

        Datatable dt2 = new Datatable();
        dt2.Columns.Add(Year);
        dt2.Columns.Add(Month);

        dt2.Rows.Add("2001","Jan");
        dt2.Rows.Add("2002","Feb");

        Datatable dtFinal = new Datatable();
        dtFinal .Columns.Add(Col1);
        dtFinal .Columns.Add(Col2);
        dtFinal .Columns.Add(Year);
        dtFinal .Columns.Add(Month);
        dtFinal .Rows.Add("Val1","Val2","2001","Jan");
        dtFinal .Rows.Add("Val3","Val4","2002","Feb");

        myDatagrid.DataSource = dtFinal;
        myDatagrid.DataBind();

        Hope this helps :) vote please

        Niladri Biswas

        modified on Saturday, June 13, 2009 11:07 AM

        1 Reply Last reply
        0
        • B Bandanenilima

          hello Can anybody tell me how to bind morethan two tables to grid view I want to add items from one table and can add year and month value from another tables

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          Bandanenilima wrote:

          I want to add items from one table and can add year and month value from another tables

          If your both datatables follow same structure, you can use DataTable.Merge[^]. But it looks like you have different structure. Obvious method would be to get a single data structure which has all the data required for binding. :)

          Navaneeth How to use google | Ask smart questions

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups