Working with asp.net DetailsView control using C# in asp.net 2.0
Author: Zunnair
Download Source Code : 908_asp.zip
In this simple article you will learn to working with asp.net datailsView 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 datalist control in form tag
<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="DataSource1" Height="50px"
Width="125px">
asp:DetailsView>
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 DetailsView control.