Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Working with asp.net FormView control using C# in asp.net 2.0

Author: Zunnair
Download Source Code : 910_aspnet_formView.zip

In this simple article you will learn to working with asp.net FormView control

 Create a web application in c#

Drag an asp.net datasource on the form and add new web.config file

Now write connection string in web.config file

<connectionStrings>

<add name="DataConnectionString" connectionString="data source= LAPTOP\SQLDEVELOPER;UID=sa;PWD=lahore;DATABASE=shoppingcart"/>

connectionStrings>

 

Then write code in default.aspx file in form tag

    <div>

        <asp:SqlDataSource ID="DSMobileCategory" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"

            OnSelecting="DSMobileCategory_Selecting" ProviderName="System.Data.SqlClient"

            SelectCommand="SELECT [PID], [Name], [Description], [Model] FROM [SHOPProducts]">asp:SqlDataSource>

   

    div>

 

Now write this code for showing data in FormView control in form tag

<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataSourceID="DataSource1">

        <ItemTemplate >

PID:

                <asp:Label ID="PIDLabel" runat="server" Text='<%# Eval("PID") %>'>asp:Label><br />

                Name:

                <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>'>asp:Label><br />

                Description:

                <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>'>

                asp:Label><br />

                Model:

                <asp:Label ID="ModelLabel" runat="server" Text='<%# Eval("Model") %>'>asp:Label><br />

                <br />

        ItemTemplate>

        asp:FormView>

Now write code on from load event

C#

protected void Page_Load(object sender, EventArgs e)

    {

        try

        {

            Label1.Text = “”;

 

        }

        catch (Exception ex)

        {

            Label1.Text = ex.Message;

        }

    }

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Try

            Label1.Text = “”

        Catch ex As Exception

            Label1.Text = ex.Message

        End Try

    End Sub

This is simple code for asp.net FormView control

Article Comments
Very good

Posted on 8/5/2009 12:47:18 PM by ravi

very very good

Posted on 11/21/2009 12:31:30 PM by dev

simple and nice coding..

Posted on 12/24/2009 12:44:54 AM by sumit

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Working with asp.net Repeater control using C# in asp.net 2.0

Disclaimer - Privacy
© 2002-2017 DevASP.net