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. gridview unable show without error

gridview unable show without error

Scheduled Pinned Locked Moved ASP.NET
databasehelptutorialquestionannouncement
11 Posts 2 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.
  • E Offline
    E Offline
    Eunice VB junior
    wrote on last edited by
    #1

    Hi ladies and gentlemen, I'm trying to retrieve sql statement to datatable then update to gridview.The datareader can read it. and able to retrieve data to txtDistID(from sql) and lblTotal(total count from datatable). But the gridview cannot show the retrieved value from datareader. but no error message found... Did i miss out anything? Can you please guide me? Thanks and appreciate...... Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click eConn = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ToString() Dim cn As New SqlConnection(eConn) Dim cmd As New SqlCommand cn.Open() strQuery = "SELECT DistID,EmpNo,EmpName,ICNo from udtDistributionAdd order by EmpNo" cmd.CommandText = strQuery cmd.Connection = cn dr = cmd.ExecuteReader() InitMyTable() Do While dr.Read Row = myTable.NewRow() Row.Item("EmpNo") = dr(1).ToString() Row.Item("EmpName") = dr(2).ToString() Row.Item("ICNo") = dr(3).ToString() Me.txtDistID.Text = dr(0).ToString() myTable.Rows.Add(Row) Loop Me.lblTotal.Text = myTable.Rows.Count cn.Close() dr.Close() End Sub Public Sub InitMyTable() myTable = New DataTable("Search") Dim EmpNo As DataColumn = New DataColumn("EmpNo") EmpNo.DataType = System.Type.GetType("System.Int32") myTable.Columns.Add(EmpNo) Dim EmpName As DataColumn = New DataColumn("EmpName") EmpName.DataType = System.Type.GetType("System.String") myTable.Columns.Add(EmpName) Dim ICNo As DataColumn = New DataColumn("ICNo") ICNo.DataType = System.Type.GetType("System.String") myTable.Columns.Add(ICNo) Dim ds As New DataSet ds = New DataSet ds.Tables.Add(myTable) Me.gvSearch.DataSource = myTable Me.gvSearch.DataBind() End Sub

    C 1 Reply Last reply
    0
    • E Eunice VB junior

      Hi ladies and gentlemen, I'm trying to retrieve sql statement to datatable then update to gridview.The datareader can read it. and able to retrieve data to txtDistID(from sql) and lblTotal(total count from datatable). But the gridview cannot show the retrieved value from datareader. but no error message found... Did i miss out anything? Can you please guide me? Thanks and appreciate...... Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click eConn = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ToString() Dim cn As New SqlConnection(eConn) Dim cmd As New SqlCommand cn.Open() strQuery = "SELECT DistID,EmpNo,EmpName,ICNo from udtDistributionAdd order by EmpNo" cmd.CommandText = strQuery cmd.Connection = cn dr = cmd.ExecuteReader() InitMyTable() Do While dr.Read Row = myTable.NewRow() Row.Item("EmpNo") = dr(1).ToString() Row.Item("EmpName") = dr(2).ToString() Row.Item("ICNo") = dr(3).ToString() Me.txtDistID.Text = dr(0).ToString() myTable.Rows.Add(Row) Loop Me.lblTotal.Text = myTable.Rows.Count cn.Close() dr.Close() End Sub Public Sub InitMyTable() myTable = New DataTable("Search") Dim EmpNo As DataColumn = New DataColumn("EmpNo") EmpNo.DataType = System.Type.GetType("System.Int32") myTable.Columns.Add(EmpNo) Dim EmpName As DataColumn = New DataColumn("EmpName") EmpName.DataType = System.Type.GetType("System.String") myTable.Columns.Add(EmpName) Dim ICNo As DataColumn = New DataColumn("ICNo") ICNo.DataType = System.Type.GetType("System.String") myTable.Columns.Add(ICNo) Dim ds As New DataSet ds = New DataSet ds.Tables.Add(myTable) Me.gvSearch.DataSource = myTable Me.gvSearch.DataBind() End Sub

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Have you stepped through the code and confirmed the data is in the table, it's not empty ?

      Christian Graus Driven to the arms of OSX by Vista.

      E 1 Reply Last reply
      0
      • C Christian Graus

        Have you stepped through the code and confirmed the data is in the table, it's not empty ?

        Christian Graus Driven to the arms of OSX by Vista.

        E Offline
        E Offline
        Eunice VB junior
        wrote on last edited by
        #3

        Hi Christian Graus, Yes i confirmed that the data is in the table. I tried to put few labels to retrieve the data. (eg:Me.lblEmpNo.Text = dr(1).ToString()) during looping, i can get the correct retrieved result. But it cannot be updated into the gridview after done.... Do i need to write code to update the data from datatable to gridview? How should i solve this problem? Pls help.... Thanks in advanced....

        C 1 Reply Last reply
        0
        • E Eunice VB junior

          Hi Christian Graus, Yes i confirmed that the data is in the table. I tried to put few labels to retrieve the data. (eg:Me.lblEmpNo.Text = dr(1).ToString()) during looping, i can get the correct retrieved result. But it cannot be updated into the gridview after done.... Do i need to write code to update the data from datatable to gridview? How should i solve this problem? Pls help.... Thanks in advanced....

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          what does your aspx look like ? If you put in a template for an empty data set, does it show instead of your data ?

          Christian Graus Driven to the arms of OSX by Vista.

          E 1 Reply Last reply
          0
          • C Christian Graus

            what does your aspx look like ? If you put in a template for an empty data set, does it show instead of your data ?

            Christian Graus Driven to the arms of OSX by Vista.

            E Offline
            E Offline
            Eunice VB junior
            wrote on last edited by
            #5

            below is my gridview setting.. i put the gridview in a div. I tried to create new gridview outside the div also not able to retrieve. and i tried to retrieve to formview also cannot. Pls help me...... Thank you very much.......

            CellPadding="3" CellSpacing="2" Font-Size="Small">

            C 1 Reply Last reply
            0
            • E Eunice VB junior

              below is my gridview setting.. i put the gridview in a div. I tried to create new gridview outside the div also not able to retrieve. and i tried to retrieve to formview also cannot. Pls help me...... Thank you very much.......

              CellPadding="3" CellSpacing="2" Font-Size="Small">

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Eunice (VB junior) wrote:

              autogeneratecolumns="False"

              OK - so where is the code to define the columns ? Did you try a style for the empty grid ? Did you look at the html to see if the div is visible ?

              Christian Graus Driven to the arms of OSX by Vista.

              E 1 Reply Last reply
              0
              • C Christian Graus

                Eunice (VB junior) wrote:

                autogeneratecolumns="False"

                OK - so where is the code to define the columns ? Did you try a style for the empty grid ? Did you look at the html to see if the div is visible ?

                Christian Graus Driven to the arms of OSX by Vista.

                E Offline
                E Offline
                Eunice VB junior
                wrote on last edited by
                #7

                The div is visible.I didn't try the empty grid as I'm not too sure how to do it. sorry coz I'm still new to asp.net. I declare the columns at InitMyTable... Sub InitMyTable() myTable = New DataTable("Search") Dim EmpNo As DataColumn = New DataColumn("EmpNo") EmpNo.DataType = System.Type.GetType("System.Int32") myTable.Columns.Add(EmpNo) Dim EmpName As DataColumn = New DataColumn("EmpName") EmpName.DataType = System.Type.GetType("System.String") myTable.Columns.Add(EmpName) Dim ICNo As DataColumn = New DataColumn("ICNo") ICNo.DataType = System.Type.GetType("System.String") myTable.Columns.Add(ICNo) Dim CostCenter As DataColumn = New DataColumn("CostCenter") CostCenter.DataType = System.Type.GetType("System.String") myTable.Columns.Add(CostCenter) Dim Division As DataColumn = New DataColumn("Division") Division.DataType = System.Type.GetType("System.String") myTable.Columns.Add(Division) Dim ds As New DataSet ds = New DataSet ds.Tables.Add(myTable) Me.gvSearch.DataSource = myTable Me.gvSearch.DataBind() End Sub i found one vb code but it's in window application (not asp.net)... it has this extra line :- datagrid1.Update() after the datareader looping... But i'm not too sure how to convert it into asp.net in asp.net, it only has gvSearch.UpdateRow(). But it cannot recognized as well. Please help.... Sorry to trouble you.... Thanks in advanced....

                C 1 Reply Last reply
                0
                • E Eunice VB junior

                  The div is visible.I didn't try the empty grid as I'm not too sure how to do it. sorry coz I'm still new to asp.net. I declare the columns at InitMyTable... Sub InitMyTable() myTable = New DataTable("Search") Dim EmpNo As DataColumn = New DataColumn("EmpNo") EmpNo.DataType = System.Type.GetType("System.Int32") myTable.Columns.Add(EmpNo) Dim EmpName As DataColumn = New DataColumn("EmpName") EmpName.DataType = System.Type.GetType("System.String") myTable.Columns.Add(EmpName) Dim ICNo As DataColumn = New DataColumn("ICNo") ICNo.DataType = System.Type.GetType("System.String") myTable.Columns.Add(ICNo) Dim CostCenter As DataColumn = New DataColumn("CostCenter") CostCenter.DataType = System.Type.GetType("System.String") myTable.Columns.Add(CostCenter) Dim Division As DataColumn = New DataColumn("Division") Division.DataType = System.Type.GetType("System.String") myTable.Columns.Add(Division) Dim ds As New DataSet ds = New DataSet ds.Tables.Add(myTable) Me.gvSearch.DataSource = myTable Me.gvSearch.DataBind() End Sub i found one vb code but it's in window application (not asp.net)... it has this extra line :- datagrid1.Update() after the datareader looping... But i'm not too sure how to convert it into asp.net in asp.net, it only has gvSearch.UpdateRow(). But it cannot recognized as well. Please help.... Sorry to trouble you.... Thanks in advanced....

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  Remove the line that says 'autogeneratecolumns="false". Set it to true. I am sure your issue is that you are not defining any columns. And, you need to buy a book on ASP.NET and work through it, unless you're just coding for fun. If someone is paying you, you should be ashamed. If you want to get paid at some point, buy a book and work through these basics.

                  Christian Graus Driven to the arms of OSX by Vista.

                  E 1 Reply Last reply
                  0
                  • C Christian Graus

                    Remove the line that says 'autogeneratecolumns="false". Set it to true. I am sure your issue is that you are not defining any columns. And, you need to buy a book on ASP.NET and work through it, unless you're just coding for fun. If someone is paying you, you should be ashamed. If you want to get paid at some point, buy a book and work through these basics.

                    Christian Graus Driven to the arms of OSX by Vista.

                    E Offline
                    E Offline
                    Eunice VB junior
                    wrote on last edited by
                    #9

                    Hi Christian Graus, Thank you so much of ur help.. It works brilliant by now... thanks for ur advice as well..

                    C 1 Reply Last reply
                    0
                    • E Eunice VB junior

                      Hi Christian Graus, Thank you so much of ur help.. It works brilliant by now... thanks for ur advice as well..

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #10

                      OK - the lesson is to turn autogeneration on, or to actually define some columns in the ASPX. Your code behind code was obviously not doing that, and it's messy anyhow, the aspx is the right place to define the columns of the grid.

                      Christian Graus Driven to the arms of OSX by Vista.

                      E 1 Reply Last reply
                      0
                      • C Christian Graus

                        OK - the lesson is to turn autogeneration on, or to actually define some columns in the ASPX. Your code behind code was obviously not doing that, and it's messy anyhow, the aspx is the right place to define the columns of the grid.

                        Christian Graus Driven to the arms of OSX by Vista.

                        E Offline
                        E Offline
                        Eunice VB junior
                        wrote on last edited by
                        #11

                        Thanks,I understand now... Chris,you are a good 'teacher'. :)

                        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