Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
BindData2();
}
}
SqlConnection con;
string constr;
string sql;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
protected void BindData()
{
{
constr = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\kategori.mdf;Integrated Security=True";
sql = "select * from [dbo].[Table]";
con = new SqlConnection(constr);
con.Open();
cmd = new SqlCommand(sql, con);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
con.Close();
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "Yazar";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();
}
}
protected void BindData2()
{
{
constr = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\kategori.mdf;Integrated Security=True";
sql = "select * from [dbo].[Table]";
con = new SqlConnection(constr);
con.Open();
cmd = new SqlCommand(sql, con);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
con.Close();
FormView1.DataSource = ds;
FormView1.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
constr = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\kategori.mdf;Integrated Security=True";
int i = DropDownList1.SelectedIndex + 1;
sql = "select * from [dbo].[Table] Where Id=" + i ;
con = new SqlConnection(constr);
con.Open();
cmd = new SqlCommand(sql, con);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
con.Close();
FormView1.DataSource = ds;
FormView1.DataBind();
}
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Font-Names="Tahoma" Font-Size="X-Large" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<br />
<br />
<asp:FormView ID="FormView1" runat="server" Font-Names="Tahoma" Font-Size="X-Large">
<ItemTemplate>
<i>
<b> ID: </b>
<%# Eval("Id") %>
<br />
<b>Yazar: </b>
<%# Eval("Yazar") %>
<br />
<b>Kitap: </b>
<%# Eval("Kitap") %>
<br />
<b>Fiyat: </b>
<%# Eval("Fiyat") %>
<br />
</i>
</ItemTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN
0 comments:
Yorum Gönder