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
 

Configuring asp.net datasource control and access record in asp datagridview using asp.net 2.0.

Author: Zunnair
Download Source Code : 906_Aspnet_Datasource.zip

In this simple article you will learn to working with asp.net datasource control and datagridview

 Create a web application in c#

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

Now write connection string in web.config file

xml version="1.0"?>

<configuration>

      <connectionStrings>

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

      connectionStrings>

      <system.web>

           

            <compilation debug="true"/>

           

            <authentication mode="Windows"/>

           

      system.web>

configuration>

 

Then write code in  default.aspx file in form tag

<form id="form1" runat="server">

    <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>

form>

 

Now put a datagrid control on form and write code on from load event

C#

protected void Page_Load(object sender, EventArgs e)

    {

        try

        {

            GridView1.DataSource = DataSource1;

            GridView1.DataBind();

        }

        catch (Exception ex)

        {

            Label1.Text = ex.Message;

        }

    }

VB

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

        Try

            GridView1.DataSource = DataSource1

            GridView1.DataBind()

        Catch ex As Exception

            Label1.Text = ex.Message

        End Try

    End Sub

This is simple code for asp.net datasource and datagridview.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Working with SESSION variable in code behind using asp.net 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net