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. Data grid!

Data grid!

Scheduled Pinned Locked Moved ASP.NET
databasecss
15 Posts 4 Posters 0 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.
  • N nclauder

    I've decided to use sql but I'm having problem with seeing my datagrid? Yet I set Property visible to true what could be the Problem Thanks.

    P Offline
    P Offline
    PandemoniumPasha
    wrote on last edited by
    #6

    you might not have called the databind() function of the datagrid.

    N 1 Reply Last reply
    0
    • P PandemoniumPasha

      you might not have called the databind() function of the datagrid.

      N Offline
      N Offline
      nclauder
      wrote on last edited by
      #7

      For sure I did call the databind() That's why I find it strange do you think I'missing something else?

      1 Reply Last reply
      0
      • N nclauder

        Hi, Is it possible to insert data into datagrid with out getting the data from a database like sql or access. Thanks.

        N Offline
        N Offline
        NanaAM
        wrote on last edited by
        #8

        Grid can be bound to any Collection type. You can create a dummy datattable as following:- DataTable dt = new DataTable("Try"); dt.Columns.Add("column1"); dt.Rows.Add("one"); dt.Rows.Add("two"); dt.Rows.Add("three"); and now set the datasource to dt. Also you need to have atleast 1 row in datasource to get the grid displayed

        Nana

        N 1 Reply Last reply
        0
        • N nclauder

          I've decided to use sql but I'm having problem with seeing my datagrid? Yet I set Property visible to true what could be the Problem Thanks.

          L Offline
          L Offline
          luckyve
          wrote on last edited by
          #9

          did you set the "data source" and "data member" for it ? then u should use data bind .

          1 Reply Last reply
          0
          • N NanaAM

            Grid can be bound to any Collection type. You can create a dummy datattable as following:- DataTable dt = new DataTable("Try"); dt.Columns.Add("column1"); dt.Rows.Add("one"); dt.Rows.Add("two"); dt.Rows.Add("three"); and now set the datasource to dt. Also you need to have atleast 1 row in datasource to get the grid displayed

            Nana

            N Offline
            N Offline
            nclauder
            wrote on last edited by
            #10

            Thank you, I was doing it like this. Hope private void Page_Load(object sender, System.EventArgs e) { if (! IsPostBack) { BindDataGrid(); } } private void BindDataGrid() { SqlCommand myCommand=new SqlCommand("SELECT * from Billing",con); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Open(); myCommand.ExecuteNonQuery(); dgbilling.DataSource=ds; dgbilling.DataBind(); con.Close(); } I had ever used this same code on another program and it worked properly. could you help me from there please Thanks.

            N P 2 Replies Last reply
            0
            • N nclauder

              Thank you, I was doing it like this. Hope private void Page_Load(object sender, System.EventArgs e) { if (! IsPostBack) { BindDataGrid(); } } private void BindDataGrid() { SqlCommand myCommand=new SqlCommand("SELECT * from Billing",con); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Open(); myCommand.ExecuteNonQuery(); dgbilling.DataSource=ds; dgbilling.DataBind(); con.Close(); } I had ever used this same code on another program and it worked properly. could you help me from there please Thanks.

              N Offline
              N Offline
              NanaAM
              wrote on last edited by
              #11

              use following code- SqlDataAdapter myAdapter=new SqlDataAdapter("SELECT * from Billing", con); con.Open(); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Close(); dgbilling.DataSource=ds; dgbilling.DataBind(); you dont need sqlcommand here at all. And one suggestion - read more about what is an adapter, dataset etc why is it used n all. I think one should know why is he/she using the object in the code.

              Nana

              N 1 Reply Last reply
              0
              • N NanaAM

                use following code- SqlDataAdapter myAdapter=new SqlDataAdapter("SELECT * from Billing", con); con.Open(); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Close(); dgbilling.DataSource=ds; dgbilling.DataBind(); you dont need sqlcommand here at all. And one suggestion - read more about what is an adapter, dataset etc why is it used n all. I think one should know why is he/she using the object in the code.

                Nana

                N Offline
                N Offline
                nclauder
                wrote on last edited by
                #12

                Thanks for the advice. But the datagrid cannot appear,

                N 1 Reply Last reply
                0
                • N nclauder

                  Thanks for the advice. But the datagrid cannot appear,

                  N Offline
                  N Offline
                  NanaAM
                  wrote on last edited by
                  #13

                  is the qurey returning records? Whats the count of rows in datasource?

                  Nana

                  N 1 Reply Last reply
                  0
                  • N NanaAM

                    is the qurey returning records? Whats the count of rows in datasource?

                    Nana

                    N Offline
                    N Offline
                    nclauder
                    wrote on last edited by
                    #14

                    In the datasource there is nonthing.. Thanks

                    1 Reply Last reply
                    0
                    • N nclauder

                      Thank you, I was doing it like this. Hope private void Page_Load(object sender, System.EventArgs e) { if (! IsPostBack) { BindDataGrid(); } } private void BindDataGrid() { SqlCommand myCommand=new SqlCommand("SELECT * from Billing",con); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Open(); myCommand.ExecuteNonQuery(); dgbilling.DataSource=ds; dgbilling.DataBind(); con.Close(); } I had ever used this same code on another program and it worked properly. could you help me from there please Thanks.

                      P Offline
                      P Offline
                      PandemoniumPasha
                      wrote on last edited by
                      #15

                      when you use data adapters you do not need to open or close the connection, it does it by itselt. if the connection was already open before calling the fill command in data-adapert, it will leave it open and if it was close, it will open it get the data and then close it. the Fill() function will get the data; so, you do not need to call the ExecuteNonQuery() command again. you might try the following: private void BindDataGrid() { SqlCommand myCommand=new SqlCommand("SELECT * from Billing",con); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds=new DataSet(); myAdapter.Fill(ds); dgbilling.DataSource=ds; dgbilling.DataBind(); } this should give the required result.

                      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