0

My background is in PHP / MySQL, but I am currently attempting to learn how to use ASP.Net with MySQL. I have created a small application that allows users to add a task. I am trying to retrieve the full list of tasks when a button is pressed. At one point, I was getting a result where by about half of the first row was displaying and nothing else (taskid & createdate). That is no longer showing up and I don't know why.

Would anyone have any advice or information that might help me to resolve this issue?

You can view the application at www.galtechsolutions.net/tasklist

My Markup is:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="viewtasks.aspx.vb" Inherits="MyTasks.ViewTasks" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="style.css" rel="Stylesheet" media="screen" />
<title>TaskList - View Tasks</title>
</head>
<body>
<a href="default.aspx">Home</a> | <a href="addtask.aspx">Add Task</a> | <a href="viewtasks.aspx">View Tasks</a>
<br /><br />
<form id="form1" runat="server">
<div>
    <asp:Button ID="gettasks" runat="server" Text="Show Tasks" class="taskbutton" />
    <br /><br />
    <asp:DataGrid ID="DataGridView1" runat="server" PageSize="5" AllowPaging="True" 
        DataKeyField="taskid" AllowSorting="True" 
        EmptyDataText="There are no data records to display" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundColumn HeaderText="taskid" DataField="taskid"></asp:BoundColumn>
    <asp:BoundColumn HeaderText="createdate" DataField="createdate"></asp:BoundColumn>
    <asp:BoundColumn HeaderText="taskname" DataField="taskname="></asp:BoundColumn>
    <asp:BoundColumn HeaderText="taskdesc" DataField="taskdesc"></asp:BoundColumn>
    <asp:BoundColumn HeaderText="duedate" DataField="duedate"></asp:BoundColumn>
    </Columns>
    </asp:DataGrid>      
    <asp:Label ID="gettaskslabel" runat="server"></asp:Label>
    <br />
    <br />
</div>
</form>
</body>
</html>

My code behind is:

Protected Sub gettasks_Click(sender As Object, e As EventArgs) Handles gettasks.Click

    Dim conn As MySqlConnection
    Dim selcmd As MySqlCommand
    Dim SQL As String

    conn = New MySqlConnection("Data Source=phaspdev1.db.10654019.hostedresource.com;Database=phaspdev1;User Id=;Password=;")
    selcmd = New MySqlCommand

    Try
        conn.Open()
        SQL = "SELECT * FROM mytasks"
        selcmd.Connection = conn
        selcmd.CommandText = SQL

        dtadapter.SelectCommand = selcmd
        dtadapter.Fill(dt)


        DataGridView1.DataSource = dt
        DataGridView1.DataBind()
        DataGridView1.DataSource = dt.Columns.Add("taskid", GetType(Integer))
        DataGridView1.DataSource = dt.Columns.Add("createdate", GetType(Date))
        DataGridView1.DataSource = dt.Columns.Add("taskname", GetType(String))
        DataGridView1.DataSource = dt.Columns.Add("taskdesc", GetType(String))
        DataGridView1.DataSource = dt.Columns.Add("duedate", GetType(Date))

        For Each dr As DataRow In dt.Rows
            dt.Rows.Add(dr)

        Next dr
        dt.AcceptChanges()

    Catch ex As Exception
        Console.WriteLine("Cannot connect to database: " & ex.Message)
    Finally
        conn.Close()
        conn.Dispose()

    End Try

End Sub

Thanks in advance,

Peter

3
  • Why are you using the old DataGrid control and not a GridView? Are you still on ASP.NET 1.1? msdn.microsoft.com/en-gb/magazine/cc163933.aspx Commented Mar 29, 2013 at 22:53
  • I tried to use your code to recreate problem. And got several errors. Can you post full code behind class ? Commented Mar 30, 2013 at 3:43
  • Just want to say a quick thanks to those who responded to this question. Their suggestions, advice, and help is much appreciated. Commented Jul 2, 2014 at 8:50

1 Answer 1

0

Try setting autoeventwireup to true. It sounds like you don't have your event handler set on the button.

http://msdn.microsoft.com/en-us/library/system.web.configuration.pagessection.autoeventwireup.aspx

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.