Alex
Alex

Reputation: 90

asp.net issue populating gridview from mysql

So here's my situation. My company bought a product which runs in the cloud. The program is great, but it lacks in it's reporting functions. So we purchased an add-on module to the package which allows us to have read-only access to the data. I planned on using this to create some reports. And yes, I could use something like crystal reports or other report generators to do this, but I have chosen to use my asp.net code. I like it, I'm familiar with it, and for this company it is the most cost effective, and easiest to update solution with my background.

So I'm using a gridview to look at some of the data. Instead of using the 'asp:sqldatasource' to lookup the data, I chose to use the code behind. Once all the data is bound to the gridview from the code behind I use the 'columns' and 'asp:templatefields' to create layout. In each one of the datarows I use the Eval() method to populate the information.

Here's the problem. The Eval method doesn't seem to recongnize things from it's datasource. The error message 'The server tag is not well formed' is thrown for my asp:labels. What am I missing here.

Here's the asp code:

<asp:GridView ID="OwnerWOS" Width="" Height=""
                BorderColor="White" EmptyDataText="" EnableViewState="false" GridLines="None" 
                OnLoad="OwnerWOS_Load" OnDataBinding="OwnerWOS_DataBinding" runat="server">
    <Columns>
        <asp:Templatefield HeaderText="Service Issue">
            <ItemTemplate>
                <asp:label ID="lblIssue" runat="server" Text="<%# Eval("issueid") %>"></asp:label>
            </ItemTemplate>
        </asp:Templatefield>
        <asp:Templatefield HeaderText="Employee">
            <ItemTemplate>
                <asp:label ID="lblEmployee" runat="server" Text="<%# Eval("EMPLOYEE") %>"></asp:label>
            </ItemTemplate>
        </asp:Templatefield>
        <asp:Templatefield HeaderText="Address">
            <ItemTemplate>
                <asp:label ID="lblAddress" runat="server" Text="<%# Eval("name") %>"></asp:label>
            </ItemTemplate>
        </asp:Templatefield>
        <asp:Templatefield HeaderText="Description">
            <ItemTemplate>
                <asp:label ID="lblDesc" runat="server" Text="<%# Eval("street1") %>"></asp:label>
            </ItemTemplate>
        </asp:Templatefield>
        <asp:Templatefield HeaderText="Work Date">
            <ItemTemplate>
                <asp:label ID="lblWorkDate" runat="server" Text="<%# Eval("duedate") %>"></asp:label>
            </ItemTemplate>
        </asp:Templatefield>
        <asp:Templatefield HeaderText="Time (h)">
            <ItemTemplate>
                <asp:label ID="lblTime" runat="server" Text="<%# Eval("owners.name") %>"></asp:label>
            </ItemTemplate>
        </asp:Templatefield>
        <asp:Templatefield HeaderText="Billed">
            <ItemTemplate>
                <asp:Label ID="lblBilled" runat="server" Text="<%# Eval("") %>"  />
            </ItemTemplate>
        </asp:Templatefield>
    </Columns>
    <HeaderStyle />
    <FooterStyle />
    <RowStyle />
    <SelectedRowStyle />
    <AlternatingRowStyle />
    <EditRowStyle />
</asp:GridView>

And the Code Behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not Page.IsPostBack Then
        'Get the first day and last day of this month to pre-populate the date fields
        Dim FirstOfMonth As String = Today.Month.ToString & "/1/" & Today.Year.ToString
        Dim LastOfMonth As String = Today.AddMonths(1).ToString & "/" & Today.AddDays(-1).ToString & "/" & Today.Year.ToString


        Dim da As New OdbcDataAdapter("SELECT DISTINCT issues.issueid, users.firstname & ' ' & users.lastname AS EMPLOYEE, property.name, " & _
                                                "property.street1, units.street1, issues.description, issuecategory.name, issues.duedate, issues.hours, owners.name " & _
                                "FROM ((((((issues RIGHT JOIN (issueproplinks RIGHT JOIN property ON issueproplinks.propid = property.propid) ON issues.issueid = issueproplinks.issueid) " & _
                                                "LEFT JOIN issuecategory ON issues.categoryid = issuecategory.categoryid) " & _
                                                "LEFT JOIN issuestatus ON issues.statusid = issuestatus.statusid) " & _
                                                "LEFT JOIN users ON issues.assignid = users.userid) " &
                                                "RIGHT JOIN ownerships ON property.propid = ownerships.propid) " & _
                                                "RIGHT JOIN owners ON ownerships.ownerid = owners.ownerid) " & _
                                                "LEFT JOIN (issueunitlinks LEFT JOIN units ON issueunitlinks.unitid = units.unitid) ON issues.issueid = issueunitlinks.issueid " & _
                                "WHERE (((issues.duedate) Between '2/1/2014' And '2/28/2014') AND ((owners.name)='LK Investment Group LLC'))" & _
                                "ORDER BY issuecategory.name, issues.duedate;", ConfigurationManager.ConnectionStrings("OA").ConnectionString)
        Dim ds As New DataSet()
        da.Fill(ds)

        OwnerWOS.DataSource = ds
        OwnerWOS.DataBind()
    End If


End Sub

Yeah the SQL statement is a bit long for a small output. But it's what I needed to do with the access this company had given me. Also, the SQL statement has been tested and does return the results I expect in other programs.

So in the asp code up top I used a variety of different access methods in the Eval statements, from providing only the name of the field, to providing the full table/field name. I've also tried removing them one at a time to see if any of them would work on their own, but they all produce the same "Malformed tag" event.

Please let me know if you need any additional details. Thanks.

Upvotes: 0

Views: 129

Answers (1)

Rick S
Rick S

Reputation: 6586

Did you try single quotes around your Text property? Double quotes around "issueid" and then double quotes around Text will not work. This is why you get the server tag is not well formed error.

Text='<%# Eval("issueid") %>'

Upvotes: 1

Related Questions