473,486 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with Datagrid (Surprising No Data!!)

Hello guys i made a Datagrid with Editing,Update and Cancel using
VS.NET. to my surprise nothing is on the screen after compilation ..

By code below:-
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class datagrid_edit
Inherits System.Web.UI.Page

Protected WithEvents MenuGrid As System.Web.UI.WebControls.DataGrid

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Sub BindDataGrid()

Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String

DBConnection = New
SqlConnection("server=(local);database=Northwind;i ntegrated
security=true;")
DBConnection.Open()
SQLString = "SELECT * FROM treetable ORDER BY FileCategoryID"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
MenuGrid.DataSource = DBReader
MenuGrid.DataBind()
DBReader.Close()
DBConnection.Close()

End Sub

Sub EditRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
MenuGrid.EditItemIndex = Args.Item.ItemIndex
BindDataGrid()
End Sub

Sub UpdateRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String

Dim FileCategoryID = CType(Args.Item.Cells(0).Controls(0),
TextBox).Text
Dim ParentID = CType(Args.Item.Cells(1).Controls(0),
TextBox).Text
Dim FileCategory = CType(Args.Item.Cells(2).Controls(0),
TextBox).Text
Dim NavigateUrl = CType(Args.Item.Cells(3).Controls(0),
TextBox).Text
Dim Target = CType(Args.Item.Cells(4).Controls(0), TextBox).Text

'Dim ItemPrice = CType(Args.Item.Cells(4).Controls(0),
TextBox).Text
'Dim ItemQuantity = CType(Args.Item.Cells(5).Controls(0),
TextBox).Text

SQLString = "UPDATE treetable SET " & _
"ParentID = '" & ParentID & "', " & _
"FileCategory = '" & Replace(FileCategory, "'", "''") & "', "
& _
"NacigateUrl = '" & Replace(NavigateUrl, "'", "''") & "', " &
_
"Target = " & Target & ", " & _
"WHERE FileCategoryID ='" & FileCategoryID & "'"
'"ItemQuantity = " & ItemQuantity & " " & _
'"WHERE ItemNumber = '" & ItemNumber & "'"

DBConnection = New
SqlConnection("server=(local);database=Northwind;i ntegrated
security=true;")
DBConnection.Open()
DBCommand = New SqlCommand(SQLString, DBConnection)
DBCommand.ExecuteNonQuery()
DBConnection.Close()

MenuGrid.EditItemIndex = -1
BindDataGrid()

End Sub
Sub CancelRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
MenuGrid.EditItemIndex = -1
BindDataGrid()
End Sub

End Class

Html Code Below:-
-------------------

<asp:DataGrid id="MenuGrid" runat="server"
OnEditCommand="EditRecord"
OnUpdateCommand="UpdateRecord"
OnCancelCommand="CancelRecord"
AutoGenerateColumns="False">

<Columns>

<asp:BoundColumn
HeaderText="ParentID"
DataField="ParentID"/>
<asp:BoundColumn
HeaderText="FileCategory"
DataField="FileCategory"/>
<asp:BoundColumn
HeaderText="NavigateUrl"
DataField="NavigateUrl"/>
<asp:BoundColumn
HeaderText="target"
DataField="target"/>

<asp:EditCommandColumn
HeaderText="Editing"
EditText="Edit"
UpdateText="Update"
CancelText="Cancel"/>

</Columns>

</asp:DataGrid>


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
2 1392
Well the reason you cant see any data is that you are not requesting for
any. I have added a couple of lines to Page_load

Also, using consider using disconnected objects like dataset for what you
are doing.
ie fetch a DataSet. use DataAdapter.Fill() for that purpose. that way you
can close the connection after the fill command is complete.
And you should also try using
Try Catch blocks..

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' for first time population of datagrid

if not Page.IsPostback then
BindDataGrid()
end if
End Sub

Sub BindDataGrid()

Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
' the rest of the code
end sub
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"naija naija" <pa*********@crazyjohns.com.au> wrote in message
news:u0**************@TK2MSFTNGP11.phx.gbl...
Hello guys i made a Datagrid with Editing,Update and Cancel using
VS.NET. to my surprise nothing is on the screen after compilation ..

By code below:-
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class datagrid_edit
Inherits System.Web.UI.Page

Protected WithEvents MenuGrid As System.Web.UI.WebControls.DataGrid

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Sub BindDataGrid()

Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String

DBConnection = New
SqlConnection("server=(local);database=Northwind;i ntegrated
security=true;")
DBConnection.Open()
SQLString = "SELECT * FROM treetable ORDER BY FileCategoryID"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
MenuGrid.DataSource = DBReader
MenuGrid.DataBind()
DBReader.Close()
DBConnection.Close()

End Sub

Sub EditRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
MenuGrid.EditItemIndex = Args.Item.ItemIndex
BindDataGrid()
End Sub

Sub UpdateRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String

Dim FileCategoryID = CType(Args.Item.Cells(0).Controls(0),
TextBox).Text
Dim ParentID = CType(Args.Item.Cells(1).Controls(0),
TextBox).Text
Dim FileCategory = CType(Args.Item.Cells(2).Controls(0),
TextBox).Text
Dim NavigateUrl = CType(Args.Item.Cells(3).Controls(0),
TextBox).Text
Dim Target = CType(Args.Item.Cells(4).Controls(0), TextBox).Text

'Dim ItemPrice = CType(Args.Item.Cells(4).Controls(0),
TextBox).Text
'Dim ItemQuantity = CType(Args.Item.Cells(5).Controls(0),
TextBox).Text

SQLString = "UPDATE treetable SET " & _
"ParentID = '" & ParentID & "', " & _
"FileCategory = '" & Replace(FileCategory, "'", "''") & "', "
& _
"NacigateUrl = '" & Replace(NavigateUrl, "'", "''") & "', " &
_
"Target = " & Target & ", " & _
"WHERE FileCategoryID ='" & FileCategoryID & "'"
'"ItemQuantity = " & ItemQuantity & " " & _
'"WHERE ItemNumber = '" & ItemNumber & "'"

DBConnection = New
SqlConnection("server=(local);database=Northwind;i ntegrated
security=true;")
DBConnection.Open()
DBCommand = New SqlCommand(SQLString, DBConnection)
DBCommand.ExecuteNonQuery()
DBConnection.Close()

MenuGrid.EditItemIndex = -1
BindDataGrid()

End Sub
Sub CancelRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
MenuGrid.EditItemIndex = -1
BindDataGrid()
End Sub

End Class

Html Code Below:-
-------------------

<asp:DataGrid id="MenuGrid" runat="server"
OnEditCommand="EditRecord"
OnUpdateCommand="UpdateRecord"
OnCancelCommand="CancelRecord"
AutoGenerateColumns="False">

<Columns>

<asp:BoundColumn
HeaderText="ParentID"
DataField="ParentID"/>
<asp:BoundColumn
HeaderText="FileCategory"
DataField="FileCategory"/>
<asp:BoundColumn
HeaderText="NavigateUrl"
DataField="NavigateUrl"/>
<asp:BoundColumn
HeaderText="target"
DataField="target"/>

<asp:EditCommandColumn
HeaderText="Editing"
EditText="Edit"
UpdateText="Update"
CancelText="Cancel"/>

</Columns>

</asp:DataGrid>


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
Hi Hermit,
Thanks for the reply.
I got that doing already guess i was tired when i wrote that code!
i will definitely amke use of dataset later!


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1457
by: VB Programmer | last post by:
I have an ASP.NET form that allows people to answer survey questions. There could be from 5 to an unlimited amt of questions, depending on which questions the admin wants to users to answer (he...
4
1272
by: KB | last post by:
I realised that if I use datagrid and datasource is a datatable, when I created a new row and while on that row I exit the datagrid (ie. without moving into the next row) and focus onto another...
2
446
by: Randy Fraser | last post by:
Is anyone using a datagrid for data entry? All I am trying to do is create a grid where the user enters an Item Number and the rest of the grid displays the information such as Description. ...
1
1191
by: adi busu via DotNetMonster.com | last post by:
Hi I need an event that could help me to update the datagrid current cell data every time it is changed. i tried with currentCellChanged but when i leave the datagrid this event does not occure...
1
1902
by: hl | last post by:
Hi, I'm a beginner and need a little help with getting data back from a web service. I am using VB.Net and have added a web reference to a Wsdl that was provided to me. My reference.vb file...
2
1246
by: teo | last post by:
I have Datagrid on an aspx page. The datagrid has data distribued on several page (that is it has navigation buttons). Question: After the data are displayed on the Datagrid, all the data...
0
1450
by: sgsiaokia | last post by:
I need help in extracting data from another source file using VBA. I have problems copying the extracted data and format into the required data format. And also, how do i delete the row that is not...
2
3544
by: gangadharampidugu | last post by:
Hi All, I need help to import data from an excel sheet to database using .NET. Can anyone please help to do this.Can i read from an excel directly into DB or by using .NET how can i access the...
1
1897
by: chandan | last post by:
Hi All! How to Export Datagrid view data to excel in ASP.net 3.5? Thanks, Chandan
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.