aspx Tarafı
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</form>
</body>
</html>
Programın kod tarafı
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;
using System.Data.SqlClient;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
private string ConnectionString
{
get { return @"Server=localhost;Database=Northwind;Trusted_Connection=true"; }
}
private void BindData()
{
SqlConnection SqlConn = new SqlConnection(ConnectionString);
String StrSql = @"SELECT * FROM Categories WHERE CategoryID IN
(SELECT CategoryID FROM Products) ";
SqlCommand SqlComm = new SqlCommand(StrSql, SqlConn);
SqlDataAdapter ad = new SqlDataAdapter(SqlComm);
DataSet ds = new DataSet();
ad.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
daha detay bilgi için http://www.forxy.net'i ziyaret edebilirsiniz
ASP.Net C# programında MS-SQL' den veri okuyup DropDownList'
- ahmethakan
- Üye
- Mesajlar: 30
- Kayıt: 03 Eki 2005 05:26
- Konum: istanbul