Feeds:
Pos
Komentar

Archive for the ‘ASP.NET’ Category

Debuging Not Enabled

Menghilangkan Debugging Not Enabled

Buat yang pertama kali mempelajari ASP.NET dan mencoba menjalankan Aplikasi yang sudah di buat, mungkin akan
di berikan tanda mata dari microsoft berupa tulisan Debugging Not Enabled, untuk menghindari hal ini kita biasanya
sudah aware menjalankannya menggunakan Ctrl+F5, kalo hal ini di lakukan berkali-kali Busyet deh, cape amat.
hal ini gara-garanya kita belum membuat file web.config, oleh karena itu kita harus membuat file web.config ini dan
mengganti tag <compilation debug=”true” >
cara membuat file nya :
1. Buka aplikasi Web anda dengan Open Web sites
2. Di Jendela Solution explorer klik kanan C:\..\website1 pilih Add New Item
3. Pilih Web Configuration File
4. Secara otomatis akan tercipta file web.config

OK Bro ngerti kan.

Read Full Post »

Repeater

REPEATER DI ASP.NET

Dalam ASP.NET ada sebuah object server control yang bernama Repeater yang fungsinya adalah menampilkan data
baik itu yang berasal dari Table ataupun View di Database untuk di Show di layar, fungsi Repeater ini berguna bila
kita ingin menampilkan data di layar secara berulang dalam bentuk label, textbox, dropdownlist dsb.
disini saya akan mempergunakan tabel mDataSiswa, berikut ini adalah tampilan web formnya :
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”frmRepeater.aspx.cs” Inherits=”frmRepeater” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html xmlns=”http://www.w3.org/1999/xhtml&#8221; >
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<table border=”0″ cellpadding=”0″ cellspacing=”0″ style=”width: 100%”>
<tr>
<td style=”width: 10%”>
Contoh penggunaan Repeater</td>
<td style=”width: 90%”>
<asp:Repeater ID=”Repeater1″ runat=”server”>
<HeaderTemplate>
<table border=”0″ cellpadding=”0″ cellspacing=”0″ style=”width:100%”>
<tr>
<th>
<asp:Label ID=”lblNIS” Text=”NIS” runat=”server” Width=”100px”></asp:Label>
</th>
<th>
<asp:Label ID=”lblNamaSiswa” Text=”Nama Siswa” runat=”server” Width=”150px”></asp:Label>
</th>
<th>
<asp:Label ID=”lblAlamat” Text=”Alamat” runat=”server” Width=”200px”></asp:Label>
</th>
<th>
<asp:Label ID=”lblTelepon” Text=”Telepon” runat=”server” Width=”100px”></asp:Label>
</th>
<th>
<asp:Label ID=”lblJenisKelamin” Text=”JenisKelamin” runat=”server” Width=”50px”></asp:Label>
</th>
<th>
<asp:Label ID=”lblNamaOrtu” Text=”Nama Ortu” runat=”server” Width=”150px”></asp:Label>
</th>
<th>
<asp:Label ID=”lblPekerjaan” Text=”Pekerjaan” runat=”server” Width=”150px”></asp:Label>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style=”width:100px” align=”center”>
<%# DataBinder.Eval(Container.DataItem,”NIS”) %>
</td>
<td style=”width:150px” align=”center”>
<%# DataBinder.Eval(Container.DataItem, “NamaSiswa”) %>
</td>
<td style=”width:200px” align=”center”>
<%# DataBinder.Eval(Container.DataItem, “Alamat”) %>
</td>
<td style=”width:100px” align=”center”>
<%# DataBinder.Eval(Container.DataItem, “Telepon”) %>
</td>
<td style=”width:50px” align=”center”>
<%# DataBinder.Eval(Container.DataItem, “JenisKelamin”) %>
</td>
<td style=”width:150px” align=”center”>
<%# DataBinder.Eval(Container.DataItem, “NamaOrtu”) %>
</td>
<td style=”width:150px” align=”center”>
<%# DataBinder.Eval(Container.DataItem, “Pekerjaan”) %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

disini kita memakai object repeater dengan tag <asp:Repeater ID=”Repeater1″ runat=”server”>
<HeaderTemplate>
<Table> adalah tag awal membuat table
<Tr> adalah tabel Row yaitu row yang ada di dalam tabel
<Th> adalah tabel header yaitu tulisa yang ada di bagian paling atas tabel
di antara tag <th></th> kita bisa memberikan object label,textbox dsb untuk di tampilkan keterangan dari column yang di buat
</HeaderTemplate>
<ItemTemplate>
<td> adalah tabel data yaitu tempat di mana data di tiap column di tampilkan
<%# DataBinder.Eval(Container.DataItem,”NIS”) %> adalah perintah ASP.NET yang mana di column tersebut akan di tampilkan NIS dari Tabel mDataSiswa
</ItemTemplate>
<FooterTemplate>
pada bagian ini adalah bagian paling bawah dari Template Repeater dan kita harus beri tag </table> bila tidak maka perintah HTML akan Invalid dan
berakibat repeater tidak benar dalam melakukan pengulangan membaca data.
</FooterTemplate>

Sedangkan perintah di Code behindnya adalah sbb:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class frmRepeater : System.Web.UI.Page
{
private string csql;
private cnConnection cn = new cnConnection();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadRepeater();
}
}

private void LoadRepeater()
{
csql = “Select * from mDataSiswa”;
DataTable dt = cn.getDataset(csql, “mDataSiswa”).Tables[0];
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}

Disini tabel mDataSiswa di simpan di Object dt (DataTable) yang selanjutnya object dt tersebut akan di gunakan oleh
object Repeater dengan nama Repeater1

Read Full Post »

web config

BERKENALAN DENGAN WEB CONFIG

Dalam ASP.NET di kenal adanya sebuah file yang bernama Web.config yang fungsinya adalah sebagai tempat referensi
dari object-object yang akan kita pakai dalam aplikasi web, seperti tentang connection string, hak user, dll, dalam
aplikasi windows base bisa di ibaratkan sebagai class utama yang mengatur koneksi dsb.

Untuk membuat web.config di ASP.NET sangatlah mudah, langkah-langkahnya adalah :
1. Buka aplikasi Web anda dengan Open Web sites
2. Di Jendela Solution explorer klik kanan C:\..\website1 pilih Add New Item
3. Pilih Web Configuration File
4. Secara otomatis akan tercipta file web.config
5. Selama masa Develop program ubah debug=true pada tag <compilation>
6. Bila menggunakan Database maka perlu di tambahkan tag <connectionStrings>
7. Contoh selengkapnya adalah sbb:

<?xml version=”1.0″?>
<!–
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
–>
<configuration>
<appSettings/>
<connectionStrings>
<add name=”DatabaseConnection” connectionString=”Server=myWindows;uid=sa;pwd=123456;database=Sekolah”/>
</connectionStrings>
<system.web>
<!–
Set compilation debug=”true” to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
–>
<compilation debug=”true” >
</compilation>
<!–
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
–>
<authentication mode=”Windows” />
<!–
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode=”RemoteOnly” defaultRedirect=”GenericErrorPage.htm”>
<error statusCode=”403″ redirect=”NoAccess.htm” />
<error statusCode=”404″ redirect=”FileNotFound.htm” />
</customErrors>
–>
</system.web>
</configuration>

di sini saya menggunakan komputer dengan nama myWindows dan SQL Server 2000 dengan uid=sa, password=123456,
databasenya Sekolah, configurasi web.config di atas masihlah sangat sederhana, untuk pembuatan web.config untuk skala
besar kita harus menggunakan tool API di Control Panel->Administrative Tools->Internet Information Service

Read Full Post »

Connection

Ada berbagai macam cara dalam membuat koneksi dari Program Aplikasi ke Database, dari yang di tuliskan langsung di form atau
pun di buat terpisah di Class tersendiri (recomended), di sini gue membuat koneksi database secara tepisah dengan nama class
cnConnection, selengkapnya adalah sbb:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for cnConnection
/// </summary>
public class cnConnection
{
SqlConnection cn;
public cnConnection()
{
}

public bool OpenConnection()
{
try
{
ConnectionStringSettings setting;
setting = ConfigurationManager.ConnectionStrings[“DatabaseConnection”];
//DatabaseConnection mengacu pada nama Connection di web.Config
if (setting != null)
{
cn = new SqlConnection(setting.ConnectionString);
cn.Open();
return true;
}
return false;
}
catch (Exception ex)
{
throw new Exception(“Error Connection to Database : ” + ex.Message);
}
}

public bool CloseConnection()
{
try
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
return true;
}
catch (Exception ex)
{
throw new Exception(“Error Connection to Database : ” + ex.Message);
}
}
public DataSet getDataset(string sql, string datasetName)
{
try
{
OpenConnection();
DataSet ds = (datasetName == string.Empty ? new DataSet() : new DataSet(datasetName));
SqlDataAdapter da = new SqlDataAdapter(sql, cn);
da.Fill(ds);
da.Dispose();
CloseConnection();
return ds;
}
catch (Exception ex)
{
cn.Close();
cn.Dispose();
throw new Exception(“Error on get Dataset : ” + ex.Message);
}
}
public void ExectureQuery(string sql)
{
try
{
OpenConnection();
if (cn.State == ConnectionState.Closed)
{
OpenConnection();
}
SqlCommand cm = new SqlCommand(sql,cn);
cm.ExecuteNonQuery();
cn.Close();
}
catch (Exception ex)
{
throw new Exception(“error on Execute Non Query: ” + ex.Message);
}
}
public bool ExecuteCommand(string sql, SqlParameterCollection colParam)
{
try
{
this.OpenConnection();
SqlCommand cmd = new SqlCommand(sql, cn);
foreach (SqlParameter param in colParam)
{
cmd.Parameters.Add(param);
}
cmd.ExecuteReader();
this.CloseConnection();
return true;
}
catch (Exception e)
{
throw new Exception(“error on Execute Command: ” + e.Message);
}
}

public bool ExecuteCommand(string sql, SqlParameter[] colParam)
{
try
{
this.OpenConnection();
SqlCommand cmd = new SqlCommand(sql, cn);
foreach (SqlParameter param in colParam)
{
cmd.Parameters.Add(param);
}
cmd.ExecuteReader();
this.CloseConnection();
return true;
}
catch (Exception e)
{
throw new Exception(“error on Execute Command: ” + e.Message);
}
}
}

ada saatnya nanti kita akan mempergunakan koneksi database macam ini, sabar ya!

Read Full Post »