2009-12-12 51 views
2

對我怎麼能格式/結構/模板GridView中的任何幫助,使從Excel電子表格的細胞中的內容將 顯示爲:GridView控件模板

<li>"looking to display data from column1 here between the li tags"</li> 
    <p>"and data from column2 here between the p tags"</p> 

<!-- and so row two from excel/objDataset1 would do the same --> 
    <li>"data from column1 here"</li> 
    <p>"data from column2 here"</p> 

etc... 

這裏是我用來獲取一個名爲碼Excel的範圍內文件到一個GridView:

Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _ 
       & "Data Source=" & Server.MapPath("Spreadsheet.xls") _ 
       & ";" & "Extended Properties=Excel 8.0;" 
    ' original code was: & "Data Source=" & Server.MapPath("../ExcelData.xls") _ ' ??? 


    Dim objConn As New OleDbConnection(sConnectionString) 
    objConn.Open() 

    ' Create new OleDbCommand to return the data from the worksheet/RangeName. 
    Dim objCmdSelect As New OleDbCommand("SELECT * FROM RangeName", objConn) 
    Dim objAdapter1 As New OleDbDataAdapter() 
    objAdapter1.SelectCommand = objCmdSelect 
    Dim objDataset1 As New DataSet() 

    ' Fill the DataSet with the information from the worksheet/RangeName. 
    objAdapter1.Fill(objDataset1, "XLData") ' ?!?!? 

    ' Build 
    GridView1.DataSource = objDataset1.Tables(0).DefaultView 
    GridView1.DataBind() 
    objConn.Close() 

----------------------------位後,我--------------------------------------

<!-- It doesn't do much a present but it does display the info --> 
<asp:GridView ID="GridView1" runat="server" style="height: 182px" 
    BackColor="Transparent" 
    BorderColor="#DEDFDE" 
    BorderStyle="None" 
    BorderWidth="1px" 
    CellPadding="4" 
    ForeColor="Black" 
    GridLines="None"> 


    <RowStyle BackColor="Transparent" 

    /> 

    <FooterStyle BackColor="#CCCC99" /> 

    <%-- <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> 
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> 
    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />--%> 
    <%-- I do not want to show the column header info from the excel file - which is coming through - also --%> 


    <AlternatingRowStyle BackColor="Transparent" /> 

</asp:GridView> 

我甚至不知道我是否應該使用GridView控件或別的東西 - 所以保持很好,如果你可以簡單的...

+0

它是什麼,現在這樣做,你不希望它做什麼?或者你還想做什麼? – Rap 2009-12-12 16:44:41

回答

1

一個GridView是一個不錯的選擇,如果你想要的電子表格外觀數據在網頁上。這正是它的設計目的。

順便說一句,它是壞的形式相互混合<li> s的<p>秒。該<p></p>可以在<li></li>內完全生活,但在<li>元素是爲了完全封閉所有其他元素。換句話說,你不應該有任何其他標籤作爲<ul>的直接子女。

編輯: 是,木匠,你靠近。在<li>之內沒有格式化問題。只需使用div將<li>中的整個格式化即可。例如:

<html> 
<head> 
<style type="text/css"> 
.Question { 
    background-color: orange; 
} 
.Answer { 
    font-weight: bold; 
} 
</style> 
</head> 
<body> 
<ol> 
<li> 
    <div> 
    <p class="Question">Q: Why is SO so awesome?</p> 
    <p class="Answer">A: Because the community writes the questions.</p> 
    </div> 
</li> 
<li> 
    <div> 
    <p class="Question">Q: Should I join?</p> 
    <p class="Answer">A: Yes, if you want to help the community by upvoting good questions and answers.</p> 
    </div> 
</li> 
<li> 
    <div> 
    <p class="Question">Q: Do you have to join?</p> 
    <p class="Answer">A: No, you can ask questions and read answers anonymously.</p> 
    </div> 
</li> 
</ol> 
</body> 
</html> 

而且不用擔心使用應答節......你沒有足夠的信譽評論/編輯,但你會在10我只是給您upvoting你的問題後更接近。 :-)

0

對不起,評論首先說唱withing應答部分 - 我沒有一個OpenID,所以這是一個解決辦法,我在這裏使用。感謝您的幫助太...

我去一個OL,其既具有一個問題,每個李,因爲它是一個答案,然後AP標籤只是看着挺對我很好,李的外觀 - 佈局明智的......應該是李文
文字然後另一個李...是沒關係?

0

只是展示我是如何得到它把工作進行到底...... &上的代碼有什麼建議?

' Create connection string variable. Modify the "Data Source" parameter as 
    ' appropriate for your environment. 
    Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _ 
       & "Data Source=" & Server.MapPath("Spreadsheet.xls") _ 
       & ";" & "Extended Properties=Excel 8.0;" 
    ' original: & "Data Source=" & Server.MapPath("../ExcelData.xls") _ 


    Dim objConn As New OleDbConnection(sConnectionString) 
    objConn.Open() 
    ' Create new OleDbCommand to return data from worksheet/RangeName. 
    Dim objCmdSelect As New OleDbCommand("SELECT * FROM RangeName", objConn) 
    Dim objAdapter1 As New OleDbDataAdapter() 
    objAdapter1.SelectCommand = objCmdSelect 

    ' Create new DataSet to hold information from the worksheet/RangeName. 
    Dim objDataset1 As New DataSet() 

    ' Fill the DataSet with the information from the worksheet/RangeName. 
    objAdapter1.Fill(objDataset1, "XLData") 

    ' Create a new DataTable object 
    Dim MyTable = New DataTable 
    MyTable = objDataset1.Tables(0) 

    ' Find how many rows are in the Rows collection 
    ' of the new DataTable object. 
    Dim numrows = MyTable.Rows.Count 

    If numrows = 0 Then 
     display_htmlstring.InnerHtml = "<p>No records found.</p>" 
    Else 

     Dim rowashtml As String 
     rowashtml = "<ol>" 

     For loop1 = 0 To numrows - 1 
' the excel rangename has column headings of Problem & Answers 
      rowashtml = rowashtml & "<li>" & Server.HtmlEncode(MyTable.Rows(loop1).Item("Problem")) _ 
       & "<p>" & Server.HtmlEncode(MyTable.Rows(loop1).Item("Answers")) & "</p></li>" 

     Next loop1 
     display_htmlstring.InnerHtml = rowashtml & "</ol>" 
    End If 

------------------------ the girdView is gone and I am now using just --------------- 

<div id="display_htmlstring" runat="server"> 
    </div> 

再次感謝說唱的幫助(李p「和在這裏太」 P禮「的東西可以hopefuly在這裏」)