Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2003
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP.Net Dynamically Updating DataGrid

    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:

    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>
    ·JGADesign·

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is the db not getting updated? I would try:

    Code:
    Sub Page_Load
            If Not IsPostBack Then
    	   BindData()
            End If
    End Sub
    does this sig match?

  • #3
    New Coder
    Join Date
    Oct 2003
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the db is getting updated, but the datagrid doesn't show the update until I refresh the page
    ·JGADesign·


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •