2014-03-05 103 views
0

所以這是我的情況。我的公司購買了一款運行在雲端的產品。該方案很好,但缺乏報告功能。所以我們購買了一個附加模塊到軟件包,使我們能夠對數據進行只讀訪問。我計劃使用它來創建一些報告。是的,我可以使用水晶報告或其他報告生成器來做到這一點,但我選擇使用我的asp.net代碼。我喜歡它,我很熟悉它,對於這家公司來說,它是最具成本效益的,並且最容易以我的背景來更新解決方案。asp.net問題從mysql填充gridview

所以我使用gridview來查看一些數據。我沒有使用'asp:sqldatasource'查找數據,而是選擇使用後面的代碼。一旦所有的數據都綁定到了後臺代碼的gridview,我使用'columns'和'asp:templatefields'來創建佈局。在每個數據行中,我使用Eval()方法來填充信息。

這是問題所在。 Eval方法似乎沒有從它的數據源中識別出事物。我的asp:標籤引發錯誤消息「服務器標記格式不正確」。我在這裏錯過了什麼。

這裏的ASP代碼:

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

而後面的代碼:

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 

呀SQL語句是有點長了一個小的輸出。但這是我需要做的與這家公司給我的訪問。此外,SQL語句已經過測試,確實可以返回我期望的其他程序的結果。

因此,在asp代碼中,我在Eval語句中使用了各種不同的訪問方法,從僅提供字段名稱到提供完整的表格/字段名稱。我也嘗試一次刪除一個,看它們中的任何一個是否會自行工作,但它們都會產生相同的「格式錯誤的標記」事件。

請讓我知道你是否需要任何額外的細節。謝謝。

回答

1

您是否嘗試過使用Text屬性的單引號? 「issueid」周圍的雙引號,然後雙引號的文本將無法工作。這就是爲什麼你會得到server tag is not well formed錯誤。

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

這將做到這一點... – Mych

+0

媽的,你知道的感覺,當你需要的所有是第二組的眼睛,或只是離開它像一個半小時,回來吧。謝謝。就是這樣。 – Alex