example of ajax control "ListSearchExtender" using asp.net
ListSearchExtender.aspx
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="ListSearchExtender.aspx.cs"
Inherits="ListSearchExtender"
%>
<%@ Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="asp"
%>
<!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">
<style type="text/css">
.PromptCSS
{
color:Snow;
font-size:large;
font-style:italic;
font-weight:bold;
background-color:DeepPink;
font-family:Courier New;
border:solid 1px Pink;
height:28px;
}
</style>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server"></asp:ToolkitScriptManager>
<div>
<asp:ListSearchExtender ID="ListSearchExtender1" runat="server"
TargetControlID="ListBox1"
PromptCssClass="PromptCSS"
>
</asp:ListSearchExtender>
<asp:ListBox
ID="ListBox1"
runat="server"
DataTextField="city" DataValueField="city"
ForeColor="SandyBrown"
BackColor="Snow"
Font-Names="Courier New"
Height="250"
Font-Bold="true"
>
</asp:ListBox>
</div>
</form>
</body>
</html>
ListSearchExtender.aspx.cs
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
System.Data.SqlClient;
public partial class ListSearchExtender : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
string
con = @"Data Source=SQLDB;Initial
Catalog=Demo;User ID=DemoD;Password=Demo1@";
SqlConnection conn = new
SqlConnection(con);
conn.Open();
string
q = "select * from pi_citydemo";
DataSet
ds = new DataSet();
SqlDataAdapter
da = new SqlDataAdapter(q,
conn);
da.Fill(ds);
ListBox1.DataSource = ds;
ListBox1.DataBind();
//
DropDownList2.Items.Insert(0, new ListItem("--select--"));
//if
(DropDownList1.SelectedIndex == -1)
//{
// DropDownList2.SelectedIndex = -1;
//}
conn.Close();
}
}
0 comments :