gridview unable show without error
-
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
-
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
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.
-
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.
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....
-
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....
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.
-
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.
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">
-
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">
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.
-
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.
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....
-
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....
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.
-
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.
Hi Christian Graus, Thank you so much of ur help.. It works brilliant by now... thanks for ur advice as well..
-
Hi Christian Graus, Thank you so much of ur help.. It works brilliant by now... thanks for ur advice as well..
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.
-
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.
Thanks,I understand now... Chris,you are a good 'teacher'. :)