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 Trick: Code Only by Charles Carroll

This grid example demonstrates creating a grid entirely in code. It is identical to the Tag based example at /freebook/learn/columnbinding.aspx.

   filename=/experiments/datagridtricks/booksfancy_code.aspx

<Test Script Below>


<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Drawing"%>
<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)
        
        dim MyDataGrid as new datagrid
        with MyDataGrid
            '.Width=Unit.Pixel(800)
            .width=Unit.Percentage(100)
            .BorderColor=Color.FromName("black")
            .ShowFooter=false
            .CellPadding=3 
            .CellSpacing=0
            .Font.Name="Verdana"
            .Font.Size=new FontUnit(12)
            .HeaderStyle.BackColor=ColorTranslator.FromHtml("#aaaadd")
        end with
        
        MyDataGrid.DataSource = new DataView(ds.Tables(0))
        FS.close()
        
        dim temp1 as new hyperlinkcolumn
        temp1.DataNavigateUrlField="isbn"
        temp1.DataNavigateUrlFormatString="http://www.amazon.com/exec/obidos/ISBN={0}/learnasp"
                temp1.Text="Buy!"
        MyDataGrid.columns.Add(temp1)
        
        dim temp2 as new boundcolumn
              temp2.HeaderText="BookCover" 
              temp2.DataField="isbn"
              temp2.DataFormatString="<img src='http://images.amazon.com/images/P/{0}.01.MZZZZZZZ.jpg' height='60' width='45'>"
        MyDataGrid.columns.Add(temp2)
        
        MyDataGrid.DataBind()
        
        dim whatever as control
        whatever=Page.FindControl("gridgoeshere")
            whatever.controls.Add(MyDataGrid)
    End Sub
</script>

<body>
<h3>The Best Books Ever</h3>
<ASP:placeholder id="gridgoeshere" runat="server"/>
</body>
</html>
Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site