E:\web\learnaspcom\htdocs\freebook\learn\ubtoc.xml LearnAsp.com - ASP ASP.net Free Lessons
Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll
<Asp.net blog>
<personal site>
xxx

DataGrid and Column Binding Part 2 by Charles Carroll

This page demonstrates how to render an XML file as a grid. It focuses on Column Binding and how it can be used as well.

We will begin using the COLUMNS templates to apply some fancy formatting. ASP+ provides data-bound objects (like listboxes, grids, etc.),  repeater templates which allow very customized layouts and columns templates.

Now we will apply some column templates to make the data display even more rich:
   filename=\experiments\bookdata\booksfancy.aspx

<Test Script Below>


<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>

<html>
<script language="VB" runat="server">
    Sub Page_Load(Src As Object, E As EventArgs) 
        Dim ds As New DataSet
        Dim FS As New FileStream(Server.MapPath("/experiments/data/books.xml"), FileMode.Open)
        ds.ReadXml(FS)
        MyDataGrid.DataSource = new DataView(ds.Tables(0))
        MyDataGrid.DataBind()
        FS.close()
    End Sub
</script>

<body>

<h3><font face="Verdana">The Best Books Ever</font> 
<span runat="server" id="MySpan"/></h3>

    <ASP:DataGrid id="MyDataGrid" runat="server"
      Width="800"
      BorderColor="black"
      ShowFooter="false" 
      CellPadding=3 
      CellSpacing="0"
      Font-Name="Verdana"
      Font-Size="8pt"
      HeaderStyle-BackColor="#aaaadd">
    
        <Columns>
          <asp:HyperLinkColumn
            DataNavigateUrlField="isbn"
            DataNavigateUrlFormatString="http://www.amazon.com/exec/obidos/ISBN={0}/learnasp"
            Text="Buy!"
          />
          
          <asp:BoundColumn
          	  HeaderText="BookCover" 
          	  DataField="isbn"
          	  DataFormatString="<img src='http://images.amazon.com/images/P/{0}.01.MZZZZZZZ.jpg' height='60' width='45'>"
          />

        </Columns>
    </ASP:DataGrid>
</body>
</html>

By the way, here is the XML source for this example:
   filename=\experiments\bookdata\books.xml

<Test Script Below>


<books>
    <book>
    <isbn>0070653623</isbn>
    <author>Jack Trout, Steve Rivkin</author>
    <title>The Power of Simplicity</title>
    <category>selfhelp</category>
    <comments>A Real Fun Read</comments>
    </book>
    
    <book>
    <isbn>0887306667</isbn>
    <author>Al Reiss, Jack Trout</author>
    <title>22 Immutable Laws of Marketing</title>
    <category>marketing</category>
    <comments>This team offers more profound advice about creating world class marketing campaigns that will be viable for a hundred years.</comments>
    </book>

    <book>
    <isbn>0887309372</isbn>
    <author>Al Reiss, Laura Reiss</author>
    <title>22 Immutable Laws of Branding</title>
    <category>marketing</category>
    <comments>This book is great for people who used 22 Immutable Laws of Marketing to build a brand and now want to strengthen that brand.</comments>
    </book>
    
    <book>
    <isbn>0679757651</isbn>
    <author>Tom Peters</author>
    <title>Circle of Innovation</title>
    <category>marketing</category>
    <comments>His most recent book is his best by far!</comments>
    </book>
    
    <book>
    <isbn>0884270610</isbn>
    <author>Eli Goldthrait</author>
    <title>The Goal</title>
    <category>management</category>
    <comments>Advocate of Theory of Constraints as applied to managment and optimization.</comments>
    </book>

    <book>
    <isbn>068485600X</isbn>
    <author>Jeff Cox, Howard Stevens</author>
    <title>Selling the Wheel</title>
    <category>management</category>
    <comments>Excellent Treatise/Novel on the entire Sales Cycle</comments>
    </book>

    <book>
    <isbn>0672316498</isbn>
    <author>Alan Cooper</author>
    <title>The Inmates Are Running The Asylum</title>
    <category>management</category>
    <comments>The father of Visual Basic and creator of the new art of Interaction Design - very valuable in designing websites. Basically the worlds most  cutting edge thinker in User Interface design aimed at simplifying software use.</comments>
    </book>
    
</books>
Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site