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> 1 1593
Well i now know what i was doing wrong!
I wasn't binding it in Page_Load.!!
"Patrick.O.Ige" wrote: 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> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christiaan |
last post by:
Hi,
I have two classes, Department and Employer, the Department contains an
ArrayList (employers) filled with Employer objects. I want to display an
ArrayList filled with Department objects using...
|
by: holy |
last post by:
Hi
If the DataSource is empty, I just want to avoid showing the Empty DataGrid with Column headers. How can I do this
TIA
Holysmoke
|
by: Sandy |
last post by:
Hello -
I didn't exactly know what to put in the Subject line, but here's my problem.
I have the following in my html. I would like to put a comma in after the
city. I tried just putting it...
|
by: Gerhard |
last post by:
I would like a DataGrid I am using to show a default number of rows (10) with
the heading, even if the dataset it is bound to returns less than that number
of rows (0-9). It is a databound grid...
|
by: Rosko |
last post by:
Hello - I'm displaying a SQL Server text field in a bound column. The text
field has line breaks (CrLf - 0D0A) but the text displays in a long string in
the DataGrid. Anybody know how to display...
|
by: Brad |
last post by:
I have a file that downloaded a CSV file for the user based upon some
information gathered from the Database. My file was working fine until
recently (I believe that my hosting company did...
|
by: ted |
last post by:
I have an old link that was widely distributed. I would now like to
put a link on that old
page that will go to a new page without displaying anything.
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
| |