B ) DROPDOWNLIST CONTROL
* DROPDOWNLIST *
Properties :- 1) Datasource = dr ;
2) Datatextfield = "column name" ;
3) Databind ( ) ;
ddlstate.DataSource = dr;
ddlstate.DataTextField = "state";
ddlstate.DataBind();
Q ) How to insertext in dropdownlist control
ddlstate.Items.Insert(0, "select");
string path = @"Data Source=.\SQLEXPRESS;Initial Catalog=vnit;Integrated "
cn = new SqlConnection(path);
cn.Open();
string k = "select * from statedb ";
cm = new SqlCommand(k, cn);
dr = cm.ExecuteReader();
ddlstate.DataSource = dr;
ddlstate.DataTextField = "state";
ddlstate.DataBind();
ddlstate.Items.Insert(0, "select");
dr.Close();
Q) If some name city is repeted then use group by
:- string k = " select city from statedb group by city "
Simple bind in Dropdownlist controle with Group by query
DDL Assigment
Searchable Dropdownlist Concept
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Rough.aspx.cs" Inherits="Rough" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<%--add jquery cdn link--%>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.js"></script>
<%--select2 js cdn--%>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js" integrity="sha512-2ImtlRlf2VVmiGZsjm9bEyhjGW4dU7B6TNwh/hx/iSByxNENtj3WVE6o/9Lj4TJeVXPi4bnOIMXFIJJAeufa0A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<%--css link select2--%>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.css" integrity="sha512-p209YNS54RKxuGVBVhL+pZPTioVDcYPZPYYlKWS9qVvQwrlzxBxkR8/48SCP58ieEuBosYiPUS970ixAfI/w/A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<%--use Script var using cssclass(ddl)--%>
<script>
$(Document).ready(function () {
$(".ddl").select2({
});
});
</script>
<style type="text/css">
.auto-style1 {
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<p class="auto-style1">
Serchable Dropdown Concept
</p>
<div class="row">
<div class="col-md-5 mb-4 pb-2">
<asp:DropDownList ID="ddlstate" runat="server" Height="97px" CssClass="ddl" Width="270px" AutoPostBack="false">
</asp:DropDownList>
<label class="form-label black" for="form3Examplev4">State</label>
<br />
</div>
<div class="col-md-7 mb-4 pb-2">
<asp:DropDownList ID="ddlcity" runat="server" Height="97px" CssClass="ddl" Width="270px" AutoPostBack="false">
</asp:DropDownList>
<label class="form-label black" for="form3Examplev4">City</label>
</div>
</div>
<p>
</p>
</form>
</body>
</html>
Code :- Same Show coding and call in pageload
Comments
Post a Comment