...

View Full Version : ASP.Net Dynamically Updating DataGrid



jgallen23
08-30-2004, 07:05 PM
I'm trying to make a page where somebody can enter some text into a text box and when they submit it, it will automatically update the datagrid on the same page, but it's not updating the page when I click submit. What am I missing?

I'll paste the code:




<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="VB" runat="server">
Dim strFname, strLname as string

Sub Insert_Pub(Source as Object, E as EventArgs)
Dim MySQL as string = "Insert into publications (pub_name) values (@pub_name1)"
Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.mappath("publications.mdb") & ";" )
Dim Cmd as New OleDbCommand(MySQL, MyConn)
cmd.Parameters.Add(New OleDbParameter("@pub_name1", pub_text.text))
MyConn.Open()
cmd.ExecuteNonQuery
BindData()
MyConn.Close()
End Sub

Sub Page_Load
BindData()
End Sub

Sub BindData()
Dim MySQL as string = "Select * from publications order by pub_name"
Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.mappath("publications.mdb") & ";" )
Dim ds as DataSet=New DataSet()
Dim Cmd as New OleDbDataAdapter(MySQL,MyConn)
Cmd.Fill(ds,"publications")
pub_list.Datasource=ds.Tables("publications").DefaultView
pub_list.DataBind()
MyConn.Close()
End Sub

</script>
</head>
<body>
<form runat="server">
<asp:textbox ID="pub_text" Columns="40" runat="server" />
<asp:button id="Button_Insert" Text="Insert" onclick="Insert_Pub" runat="server" /><br />
<asp:label ID="label1" runat="server" />
<asp:datagrid runat="server" ID="pub_list"></asp:datagrid>
</form>
</body>
</html>

allida77
08-30-2004, 10:24 PM
Is the db not getting updated? I would try:



Sub Page_Load
If Not IsPostBack Then
BindData()
End If
End Sub

jgallen23
08-31-2004, 12:59 AM
the db is getting updated, but the datagrid doesn't show the update until I refresh the page



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum