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 bind of datagrid with dataset

data bind of datagrid with dataset

Scheduled Pinned Locked Moved ASP.NET
database
20 Posts 5 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.
  • R Rock Star

    Hi, I put this code in it but still I cant see my datagrid.

    Rock Star

    I Offline
    I Offline
    Imran Khan Pathan
    wrote on last edited by
    #4

    Rock Star. wrote:

    I put this code in it but still I cant see my datagrid.

    First check your query.It returns any dataset.Run that query in Sql Query Analyzer. regard kHan

    please don't forget to vote on the post that helped you.

    R 1 Reply Last reply
    0
    • I Imran Khan Pathan

      Rock Star. wrote:

      I put this code in it but still I cant see my datagrid.

      First check your query.It returns any dataset.Run that query in Sql Query Analyzer. regard kHan

      please don't forget to vote on the post that helped you.

      R Offline
      R Offline
      Rock Star
      wrote on last edited by
      #5

      Hi, I checked my query its perfect. I checked dataset.tables(0).rows.count and its returning number of rows in the dataset. I dont everywhere same code is given to bind the datagrid to dataset. I dont know why it is not working in my case.

      Rock Star

      I 1 Reply Last reply
      0
      • R Rock Star

        Hi, I checked my query its perfect. I checked dataset.tables(0).rows.count and its returning number of rows in the dataset. I dont everywhere same code is given to bind the datagrid to dataset. I dont know why it is not working in my case.

        Rock Star

        I Offline
        I Offline
        Imran Khan Pathan
        wrote on last edited by
        #6

        ProductDG.DataSource = m_DataSet.DefaultViewManager Is there any reason to use DefaultViewManager. You can also do in this way. ProductDG.DataSource = m_DataSet.Tables[0] or If m_DataSet.DefaultViewManager <> Nothing Then //bind DataGrid Else //Is null End If Regard Khan

        please don't forget to vote on the post that helped you.

        R 1 Reply Last reply
        0
        • I Imran Khan Pathan

          ProductDG.DataSource = m_DataSet.DefaultViewManager Is there any reason to use DefaultViewManager. You can also do in this way. ProductDG.DataSource = m_DataSet.Tables[0] or If m_DataSet.DefaultViewManager <> Nothing Then //bind DataGrid Else //Is null End If Regard Khan

          please don't forget to vote on the post that helped you.

          R Offline
          R Offline
          Rock Star
          wrote on last edited by
          #7

          hi I tried ProductDG.DataSource = m_DataSet.Tables[0] in my code but same result. I cant see my datasrid control. But when I am trying to put the condition for m_DataSet.DefaultViewManager <> Nothing it is going in the else part and showing nothing for defaultviemanager.

          Rock Star

          A 1 Reply Last reply
          0
          • R Rock Star

            Hi, I put this code in it but still I cant see my datagrid.

            Rock Star

            V Offline
            V Offline
            Venkatesh Mookkan
            wrote on last edited by
            #8

            Try like,

            ' Bind the DataGrid to the DataSet's first DataTable.
            ProductDG.DataSource = m_DataSet.Tables("Demo")
            ProductDG.DataBind()
            

            Tell me one thing... Does your DataGrid has columns bounded? Could you please post your *.aspx HTML?

            Venkatesh Mookkan My: Website | Yahoo Group | Blog Spot

            R 1 Reply Last reply
            0
            • V Venkatesh Mookkan

              Try like,

              ' Bind the DataGrid to the DataSet's first DataTable.
              ProductDG.DataSource = m_DataSet.Tables("Demo")
              ProductDG.DataBind()
              

              Tell me one thing... Does your DataGrid has columns bounded? Could you please post your *.aspx HTML?

              Venkatesh Mookkan My: Website | Yahoo Group | Blog Spot

              R Offline
              R Offline
              Rock Star
              wrote on last edited by
              #9

              Yes my datagrid has one bounded column in .aspx file but wen i run the page I am getting an error for "A field or property with the name 'Column name' was not found on the selected data source." but my table has the column I have specified in bond column section of datagrid. This is the aspx code for datagrid
              Rock Star

              S 1 Reply Last reply
              0
              • R Rock Star

                Yes my datagrid has one bounded column in .aspx file but wen i run the page I am getting an error for "A field or property with the name 'Column name' was not found on the selected data source." but my table has the column I have specified in bond column section of datagrid. This is the aspx code for datagrid
                Rock Star

                S Offline
                S Offline
                Sherin Iranimose
                wrote on last edited by
                #10

                Rock Star. wrote:

                datafield="'Column name"

                Why there is a single quotation(') near Column name

                **$**herin Iranimose

                R 1 Reply Last reply
                0
                • S Sherin Iranimose

                  Rock Star. wrote:

                  datafield="'Column name"

                  Why there is a single quotation(') near Column name

                  **$**herin Iranimose

                  R Offline
                  R Offline
                  Rock Star
                  wrote on last edited by
                  #11

                  Its a typing mistake there is no single quote in the code. Do u know why there is no data in my data grid.

                  Rock Star

                  S 1 Reply Last reply
                  0
                  • R Rock Star

                    Its a typing mistake there is no single quote in the code. Do u know why there is no data in my data grid.

                    Rock Star

                    S Offline
                    S Offline
                    Sherin Iranimose
                    wrote on last edited by
                    #12

                    Use a datatable instead of dataset. and try the GV is displaying or not.

                    **$**herin Iranimose

                    R 1 Reply Last reply
                    0
                    • S Sherin Iranimose

                      Use a datatable instead of dataset. and try the GV is displaying or not.

                      **$**herin Iranimose

                      R Offline
                      R Offline
                      Rock Star
                      wrote on last edited by
                      #13

                      I tried data table too but same result.

                      Rock Star

                      S 1 Reply Last reply
                      0
                      • R Rock Star

                        I tried data table too but same result.

                        Rock Star

                        S Offline
                        S Offline
                        Sherin Iranimose
                        wrote on last edited by
                        #14

                        can you please do a copy paste of the gridview HTML code and the vb code. So that I can simulate the same thing and find out the problem.

                        **$**herin Iranimose

                        R 1 Reply Last reply
                        0
                        • R Rock Star

                          hi I tried ProductDG.DataSource = m_DataSet.Tables[0] in my code but same result. I cant see my datasrid control. But when I am trying to put the condition for m_DataSet.DefaultViewManager <> Nothing it is going in the else part and showing nothing for defaultviemanager.

                          Rock Star

                          A Offline
                          A Offline
                          Ariel Kazeed
                          wrote on last edited by
                          #15

                          Hi, why are you using m_DataSet.DefaultViewManager anyhow? I always use things like...

                          Dataset ds = GetDataset();
                          Gridview.Datasource = ds.Tables[0]; // Even with a .CreateDataReader if you want to
                          GridView.Databind();

                          And works perfectly fine. I assume the GridView is visible on the aspx marking right? (Sorry for this obvious question, but you never know...)

                          Kazz


                          "Users are there to click on things, not think. Let the archs do the damn thinking."

                          1 Reply Last reply
                          0
                          • S Sherin Iranimose

                            can you please do a copy paste of the gridview HTML code and the vb code. So that I can simulate the same thing and find out the problem.

                            **$**herin Iranimose

                            R Offline
                            R Offline
                            Rock Star
                            wrote on last edited by
                            #16

                            This is the aspx code u asked for <asp:GridView ID="ProductDG" runat="server" AutoGenerateColumns=false AllowPaging="true" PageSize=10 Height="182px" Width="155px"> <Columns> <asp:BoundField DataField="column Name" HeaderText="Name" SortExpression="column Name" > <HeaderStyle Font-Names="Arial" Font-Size="12px" /> <ItemStyle Font-Names="Arial" Font-Size="12px" /> </asp:BoundField> </Columns> </asp:GridView> and this is the vb code for the databinding Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim Productds As New DataSet Dim m_DataAdapter As New SqlClient.SqlDataAdapter( _ "query", "connectionstring") Dim m_DataSet As New DataSet ' Fill the DataSet. m_DataAdapter.Fill(m_DataSet, "Demo") ' Bind the DataGrid to the DataSet's first DataTable. ProductDG.DataSource = m_DataSet.DefaultViewManager ProductDG.DataMember = "Demo" End sub

                            Rock Star

                            I S 3 Replies Last reply
                            0
                            • R Rock Star

                              This is the aspx code u asked for <asp:GridView ID="ProductDG" runat="server" AutoGenerateColumns=false AllowPaging="true" PageSize=10 Height="182px" Width="155px"> <Columns> <asp:BoundField DataField="column Name" HeaderText="Name" SortExpression="column Name" > <HeaderStyle Font-Names="Arial" Font-Size="12px" /> <ItemStyle Font-Names="Arial" Font-Size="12px" /> </asp:BoundField> </Columns> </asp:GridView> and this is the vb code for the databinding Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim Productds As New DataSet Dim m_DataAdapter As New SqlClient.SqlDataAdapter( _ "query", "connectionstring") Dim m_DataSet As New DataSet ' Fill the DataSet. m_DataAdapter.Fill(m_DataSet, "Demo") ' Bind the DataGrid to the DataSet's first DataTable. ProductDG.DataSource = m_DataSet.DefaultViewManager ProductDG.DataMember = "Demo" End sub

                              Rock Star

                              I Offline
                              I Offline
                              Imran Khan Pathan
                              wrote on last edited by
                              #17

                              Rock Star. wrote:ProductDG.DataSource = m_DataSet.DefaultViewManager ProductDG.DataMember = "Demo" Dear You set Datasource but you need to bind Datagrid after that ProductDG.DataBind() Also If someone tells you to post code then post your complete code. Here you used "column name" but you should post with column field name which you want to bind Now dont tell that you did mistake here to post code regard kHan please don't forget to vote on the post that helped you.

                              1 Reply Last reply
                              0
                              • R Rock Star

                                This is the aspx code u asked for <asp:GridView ID="ProductDG" runat="server" AutoGenerateColumns=false AllowPaging="true" PageSize=10 Height="182px" Width="155px"> <Columns> <asp:BoundField DataField="column Name" HeaderText="Name" SortExpression="column Name" > <HeaderStyle Font-Names="Arial" Font-Size="12px" /> <ItemStyle Font-Names="Arial" Font-Size="12px" /> </asp:BoundField> </Columns> </asp:GridView> and this is the vb code for the databinding Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim Productds As New DataSet Dim m_DataAdapter As New SqlClient.SqlDataAdapter( _ "query", "connectionstring") Dim m_DataSet As New DataSet ' Fill the DataSet. m_DataAdapter.Fill(m_DataSet, "Demo") ' Bind the DataGrid to the DataSet's first DataTable. ProductDG.DataSource = m_DataSet.DefaultViewManager ProductDG.DataMember = "Demo" End sub

                                Rock Star

                                S Offline
                                S Offline
                                Sherin Iranimose
                                wrote on last edited by
                                #18

                                Try this, It is working for me. Dim Productds As New DataSet Dim m_DataAdapter As New SqlClient.SqlDataAdapter( _ "query", "connectionstring") Dim m_DataSet As New DataSet ' Fill the DataSet. m_DataAdapter.Fill(m_DataSet) ' Bind the DataGrid to the DataSet's first DataTable. ProductDG.DataSource = m_DataSet ProductDG.DataBind();

                                **$**herin Iranimose

                                1 Reply Last reply
                                0
                                • R Rock Star

                                  This is the aspx code u asked for <asp:GridView ID="ProductDG" runat="server" AutoGenerateColumns=false AllowPaging="true" PageSize=10 Height="182px" Width="155px"> <Columns> <asp:BoundField DataField="column Name" HeaderText="Name" SortExpression="column Name" > <HeaderStyle Font-Names="Arial" Font-Size="12px" /> <ItemStyle Font-Names="Arial" Font-Size="12px" /> </asp:BoundField> </Columns> </asp:GridView> and this is the vb code for the databinding Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim Productds As New DataSet Dim m_DataAdapter As New SqlClient.SqlDataAdapter( _ "query", "connectionstring") Dim m_DataSet As New DataSet ' Fill the DataSet. m_DataAdapter.Fill(m_DataSet, "Demo") ' Bind the DataGrid to the DataSet's first DataTable. ProductDG.DataSource = m_DataSet.DefaultViewManager ProductDG.DataMember = "Demo" End sub

                                  Rock Star

                                  S Offline
                                  S Offline
                                  Sherin Iranimose
                                  wrote on last edited by
                                  #19

                                  The problem with you code is 1.

                                  Rock Star. wrote:

                                  m_DataSet.DefaultViewManager

                                  You can directly use m_DataSet or one table inside the dadta set 2. Like Pathan told You are not binding the grid view. using ProductDG.DataBind() So when i told you to use datatable you used it but you didnot bind it to GV. I think now you got the problem.

                                  **$**herin Iranimose

                                  R 1 Reply Last reply
                                  0
                                  • S Sherin Iranimose

                                    The problem with you code is 1.

                                    Rock Star. wrote:

                                    m_DataSet.DefaultViewManager

                                    You can directly use m_DataSet or one table inside the dadta set 2. Like Pathan told You are not binding the grid view. using ProductDG.DataBind() So when i told you to use datatable you used it but you didnot bind it to GV. I think now you got the problem.

                                    **$**herin Iranimose

                                    R Offline
                                    R Offline
                                    Rock Star
                                    wrote on last edited by
                                    #20

                                    Thanx a lot guys its working now.

                                    Rock Star

                                    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