ASP.NET Code
  Home arrow ASP.NET Code arrow Create Bound Columns Dynamically
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET CODE

Create Bound Columns Dynamically
By: Sushila Bowalekar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2002-06-21

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

     

    A sample code to Create Bound Columns Dynamically- The demonstration shows the Dropdownlist poulated with the Tables in Database pubs on Page_Load event - On selection of the table from the dropdown it display the fieldnames in the listbox. - If no date is selected from the listbox the requiredfieldvalidator shows the error accordingly - As there are two buttons and the requiredfield validator should show error only when the button to show column data is clicked button showing the column names has the causevalidation = false - For multiselect of the listbox the listitem is being used.[bold]Step 1: main.aspx[/bold]


    <TABLE id="Table1" style="Z-INDEX: 108; LEFT: 44px; POSITION: absolute; TOP: 24px" cellSpacing="1" cellPadding="1" width="100%" border="1"

    <
    TR

    <
    TD> <asp:Label id="Label1" runat="server"Tables</asp:Label></TD

    <
    TD> <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList></TD>

     <
    TD> <asp:Button id="btnShow" runat="server" Text="Show Column Info" CausesValidation="False"></asp:Button></TD>

     </
    TR

    <
    TR

    <
    TD style="HEIGHT: 29px"> <asp:Label id="Label3" runat="server">Column Information</asp:Label></TD

    <
    TD style="HEIGHT: 29px"> <asp:ListBox id="ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox> <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Select Item(s) from List box" ControlToValidate="ListBox1"></asp:RequiredFieldValidator></TD

    <
    TD style="HEIGHT: 29px"> <asp:Button id="Button1" runat="server" Text="Show Data"></asp:Button></TD

    </
    TR

    <
    TR>

     <
    TD></TD

    <
    TD> <asp:DataGrid id="DataGrid1" AutoGenerateColumns="false" runat="server" Height="100px"></asp:DataGrid></TD

    <
    TD></TD

    </
    TR

    </
    TABLE

    [bold]Step 2:main.aspx.vb[/bold]


    Dim myconnection As SqlClient.SqlConnection

    Dim myda 
    As SqlClient.SqlDataAdapter

    Dim ds 
    As DataSet

    Private Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Load

    'Put user code to initialize the page here

    myconnection = New SqlClient.SqlConnection("Server=localhost;uid=sa;password=;database=pubs;")

    If Not Page.IsPostBack Then

         myda = New SqlClient.SqlDataAdapter("Select * from sysobjects where xtype='
    u'", myconnection)

         ds = New DataSet()

         myda.Fill(ds, "AllTables")

         DropDownList1.DataTextField = "name"

         DropDownList1.DataSource = ds.Tables(0)

         DropDownList1.DataBind()

    End If

    End Sub

    Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click

         ListBox1.Items.Clear()

         myda = New SqlClient.SqlDataAdapter("Select * from " & DropDownList1.SelectedItem.Text, myconnection)

        ds = New DataSet()

        myda.Fill(ds, "TableName")

        Dim dc As DataColumn

        For Each dc In ds.Tables(0).Columns

            ListBox1.Items.Add(dc.ColumnName)

        Next

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

         myda = New SqlClient.SqlDataAdapter("Select * from " & DropDownList1.SelectedItem.Text, myconnection)

        ds = New DataSet()

        myda.Fill(ds, "TableName")

        Dim i As Integer

        Dim li As ListItem

        For Each li In ListBox1.Items

          If li.Selected Then

             Dim objbc As New BoundColumn()

            objbc.DataField = li.Text

            objbc.HeaderText = li.Text

            DataGrid1.Columns.Add(objbc)

            DataGrid1.DataSource = ds.Tables(0)

            DataGrid1.DataBind()

         End If

       Next

    End Sub


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP.NET Code Articles
    More By Sushila Bowalekar

     

    IBM® developerWorks developerWorks - FREE Tools!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! Applying lean thinking to the governance of software development

    Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations.
    FREE! Go There Now!


    NEW! Did you say mainframe? e-kit

    Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise.
    FREE! Go There Now!


    NEW! Evaluate WebSphere Extended Deployment Compute Grid V6.1

    Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 2: Automate builds for a real-world Tomcat project

    Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available.
    FREE! Go There Now!


    NEW! Using the Eclipse SOA Tools Platform plug-in and Apache Tuscany

    The Eclipse SOA Tools Platform (STP) plug-in and Apache Tuscany simplifies services development through the use of the popular Eclipse development environment. Apache Tuscany has also been integrated with the STP to provide a Service Component Architecture (SCA) Java run time for the services you create, allowing you to annotate your service using the SCA standard and Apache Tuscany annotations. In this tutorial, you will see STP and Apache Tuscany in action, through the creation of a Remote Method Invocation (RMI) service.
    FREE! Go There Now!


    NEW! Web development with Eclipse Europa, Part 1: The Java EE for Eclipse

    It's a good time to be a Web developer. You've never had more choices in terms of technologies. There are so many great open source Web servers, databases, programming languages, and development frameworks. No matter what combination of technologies you prefer to work with, there is an integrated development environment (IDE) that can increase your productivity: Eclipse. In this tutorial, Part 1 of a three-part "Web development with Eclipse Europa" series on how to use Eclipse for Web development with Java technology, PHP, and Ruby, we'll see how the latest release of Eclipse -- Europa -- can be used to rapidly develop Java Web applications. We'll use Java Platform, Enterprise Edition 5 (Java EE) for Eclipse to build a Web application for tracking and calculating baseball statistics.
    FREE! Go There Now!


    NEW! Web development with Eclipse Europa, Part 2: The Java EE for Eclipse

    No matter what combination of technologies you prefer to work with as a Web developer, Eclipse is a single integrated development environment (IDE) that can increase your productivity. In Part 2, we'll see how easy it is to develop PHP applications using a different set of Eclipse plug-ins, collectively known as the PHP Development Toolkit (PDT.)
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    FREE! Go There Now!


    NEW! Webcast: What is new in Viper 2 for developers?

    Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway