Merhaba arkadaşlar bu makalemizde Asp.net te CheckBoxList kullanımı ile ilgili basit bir örnek yapacağız.
Screenshot
Şekil 1
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)
{
baglacboxlist();
}
}
private void baglacboxlist()
{ try
{
DataSet ds = dataSet("Select * from [dbo].[Table]");
CheckBoxList1.DataSource = ds;
CheckBoxList1.DataTextField = "Yazar";
CheckBoxList1.DataValueField = "Id";
CheckBoxList1.DataBind();
}
catch (Exception){}
}
private DataSet dataSet(string sorgu)
{ DataSet ds = new DataSet();
try
{ string str = "Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\kategori.mdf;Integrated Security=True;Connect Timeout=30";
SqlConnection baglan = new SqlConnection(str);
SqlDataAdapter da = new SqlDataAdapter(sorgu, baglan);
da.Fill(ds);
}
catch (Exception){}
return ds;
}
}
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:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList>
</div>
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki makalede
görüşmek üzere. Bahadır ŞAHİN