Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Datagrid


Message #1 by "easykid" <qiqiliu@h...> on Sat, 3 Feb 2001 16:38:26 -0000
  is anyone know how to at runtime create the datagrid,set the

properties,such as adding Boundcolumns and setting datatextfield and

datavaluefield,also set the

DataNavigateURLfield etc.,since i want to load the one table and bind with

datagrid to get features provided by design time such as navigateURL

(i only know table name and  structure at runtime),can not databind at

design time

 

 Thank



 Daniel

Message #2 by =?iso-8859-1?Q?Fredrik_Norm=E9n?= <fredrik.normen@e...> on Mon, 5 Feb 2001 08:58:46 +0100
Here is an example:



<html>



<script language="VB" runat=server>



        Sub Page_Load(Sender as Object, E as EventArgs)



		dim myArray as ArrayList = new ArrayList()

		myArray.Add ("hello","1")

		myArray.Add ("hello2","2")



             ' Dynamically create a new datagrid

             Dim MyDataGrid as New DataGrid



             MyDataGrid.DataSource = myArray



             ' Dynamically Add DataGrid into the Page

             Area.Controls.Add(MyDataGrid)



             MyDataGrid.DataBind()



        End Sub



    </script>



    <body>

        <asp:label id="Area" runat=server/>

    </body>



</html>





/Fredrik Normén





-----Original Message-----

From: easykid [mailto:qiqiliu@h...]

Sent: den 3 februari 2001 17:38

To: ASP+

Subject: [aspx] Datagrid





  is anyone know how to at runtime create the datagrid,set the

properties,such as adding Boundcolumns and setting datatextfield and

datavaluefield,also set the

DataNavigateURLfield etc.,since i want to load the one table and bind with

datagrid to get features provided by design time such as navigateURL

(i only know table name and  structure at runtime),can not databind at

design time



 Thank



 Daniel





Message #3 by Susan Warren <swarren@m...> on Mon, 5 Feb 2001 06:20:42 -0800
Here's a more detailed example that shows dynamically creating columns too:

a bound column and a hyperlink column.  



hth,

Susan





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





<html>



<script language="VB" runat=server>



        Sub Page_Load(Sender as Object, E as EventArgs)



            ' Dynamically create a new datagrid

            Dim MyDataGrid as New DataGrid



            MyDataGrid.DataSource = CreateDataSource()



            ' Set up the columns collection programatically, not

automatically

            MyDataGrid.AutoGenerateColumns = false



            ' Add a bound column

            Dim bc1 as new BoundColumn

            bc1.DataField = "IntegerValue"

            bc1.HeaderText = "Record ID"

            MyDataGrid.Columns.Add (bc1)



            ' Add a hyperlink column

            Dim hc1 as new HyperLinkColumn

            hc1.DataTextField = "StringValue"

            hc1.DataTextFormatString = "Show details for {0}"

            hc1.DataNavigateUrlField="IntegerValue"

            hc1.DataNavigateUrlFormatString="details.aspx?ID={0}"

            hc1.HeaderText="Show me more"

            MyDataGrid.Columns.Add (hc1)



            ' Dynamically Add DataGrid into the Page

            Area.Controls.Add(MyDataGrid)



            MyDataGrid.DataBind()



        End Sub





        Function CreateDataSource() As ICollection



		' dummy datasource

            Dim dt As DataTable

            Dim dr As DataRow

            Dim i As Integer



            'create a DataTable

            dt = New DataTable

            dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer)))

            dt.Columns.Add(New DataColumn("StringValue", GetType(String)))



            'Make some rows and put some sample data in

            For i = 1 To 9

                dr = dt.NewRow()

                dr(0) = i

                dr(1) = "Item " + i.ToString()

                dt.Rows.Add(dr)

            Next



            'return a DataView to the DataTable

            CreateDataSource = New DataView(dt)



        End Function



    </script>



    <body>

        <asp:label id="Area" runat=server/>

    </body>



</html>









-----Original Message-----

From: Fredrik Normén [mailto:fredrik.normen@e...]

Sent: Sunday, February 04, 2001 11:59 PM

To: ASP+

Subject: [aspx] RE: Datagrid





Here is an example:



<html>



<script language="VB" runat=server>



        Sub Page_Load(Sender as Object, E as EventArgs)



		dim myArray as ArrayList = new ArrayList()

		myArray.Add ("hello","1")

		myArray.Add ("hello2","2")



             ' Dynamically create a new datagrid

             Dim MyDataGrid as New DataGrid



             MyDataGrid.DataSource = myArray



             ' Dynamically Add DataGrid into the Page

             Area.Controls.Add(MyDataGrid)



             MyDataGrid.DataBind()



        End Sub



    </script>



    <body>

        <asp:label id="Area" runat=server/>

    </body>



</html>





/Fredrik Normén





-----Original Message-----

From: easykid [mailto:qiqiliu@h...]

Sent: den 3 februari 2001 17:38

To: ASP+

Subject: [aspx] Datagrid





  is anyone know how to at runtime create the datagrid,set the

properties,such as adding Boundcolumns and setting datatextfield and

datavaluefield,also set the

DataNavigateURLfield etc.,since i want to load the one table and bind with

datagrid to get features provided by design time such as navigateURL

(i only know table name and  structure at runtime),can not databind at

design time



 Thank



 Daniel






  Return to Index