DataGrid Edit command problems
Hi,
I’m trying to use Datagrid edit feature. When I press Edit button Datagrid shows Update and Cancel buttons, but I still can’t see text boxes. Please take a look at my code and say where is the problem.
P. S. Sorry for my English
VB Code:
Dim cSQConnection As SqlConnection
Dim cSqlCommand As SqlCommand
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
cSQConnection = New SqlConnection("server=MySQLServer;database=MyDatabase;")
cSQConnection.Open()
cSqlCommand = New SqlCommand("SELECT * FROM Projects", cSQConnection)
DataGrid1.DataSource = cSqlCommand.ExecuteReader()
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
BindData()
End Sub
Re: DataGrid Edit command problems
What does the Datagrid code on the ASPX file look like?
Re: DataGrid Edit command problems
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebApplication3.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 72px" runat="server"
Width="472px" Height="184px"></asp:DataGrid>
</form>
</body>
</HTML>
Re: DataGrid Edit command problems
OK. The reader is not an updatable recordset object, so the code cannot automatically handle the proper updates, etc to the database.
In reality, it is better for you to handle it anyway.
Here is a link for you, use the VB examples, not the J#.
http://samples.gotdotnet.com/quickst...ataaccess.aspx