TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
shubham prakash
NA
16
1.3k
select all checkbox in dropdown
Oct 25 2013 9:06 AM
my code is:
aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ddn.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>Grid Validation</title>
<script language="javascript" type="text/javascript">
function showdiv() {
document.getElementById("divChkList").style.display = "block";
}
function showdivonClick() {
var objDLL = document.getElementById("divChkList");
if (objDLL.style.display == "block")
objDLL.style.display = "none";
else
objDLL.style.display = "block";
}
function getSelectedItem(lstValue, lstNo, lstID, ctrlType) {
var noItemChecked = 0;
var ddlReport = document.getElementById("ddlChkList");
var selectedItems = "";
var arr = document.getElementById("chkLstItem").getElementsByTagName('input');
var arrlbl = document.getElementById("chkLstItem").getElementsByTagName('label');
var objLstId = document.getElementById('hidList');
for (i = 0; i < arr.length; i++) {
checkbox = arr[i];
if (i == lstNo) {
if (ctrlType == 'anchor') {
if (!checkbox.checked) {
checkbox.checked = true;
}
else {
checkbox.checked = false;
}
}
}
if (checkbox.checked) {
if (selectedItems == "") {
selectedItems = arrlbl[i].innerText;
}
else {
selectedItems = selectedItems + "," + arrlbl[i].innerText;
}
noItemChecked = noItemChecked + 1;
}
}
ddlReport.title = selectedItems;
var Text = ddlReport.options[ddlReport.selectedIndex].text;
if (noItemChecked == 1)
ddlReport.options[ddlReport.selectedIndex].text = lstValue;
else
ddlReport.options[ddlReport.selectedIndex].text = noItemChecked + " Items";
document.getElementById('hidList').value = ddlReport.options[ddlReport.selectedIndex].text;
}
document.onclick = check;
function check(e) {
var target = (e && e.target) || (event && event.srcElement);
var obj = document.getElementById('divChkList');
var obj1 = document.getElementById('ddlChkList');
if (target.id != "alst" && !target.id.match("chkLstItem")) {
if (!(target == obj || target == obj1)) {
obj.style.display = 'none'
}
else if (target == obj || target == obj1) {
if (obj.style.display == 'block') {
obj.style.display = 'block';
}
else {
obj.style.display = 'none';
document.getElementById('ddlChkList').blur();
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td valign="top" style="width: 165px">
<asp:PlaceHolder ID="ppl" runat="server" ></asp:PlaceHolder>
</td>
</tr>
</table>
<asp:HiddenField ID="hidList" runat="server" />
</form>
</body>
</html>
my .cs code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddl = new DropDownList();
ddl.ID = "ddlChkList";
ListItem lstItem = new ListItem();
ddl.Items.Insert(0, lstItem);
ddl.Width = new Unit(155);
ddl.Attributes.Add("onmousedown", "showdivonClick()");
//ddl.Attributes.Add("onclick", "chkall()");
CheckBoxList chkBxLst = new CheckBoxList();
chkBxLst.ID = "chkLstItem";
chkBxLst.Attributes.Add("onmouseover", "showdiv()");
//chkBxLst.Attributes.Add("onclick", "chkall()");
DataTable dtListItem = GetListItem();
int rowNo = dtListItem.Rows.Count;
string lstValue = string.Empty;
string lstID = string.Empty;
for (int i = 0; i < rowNo - 1; i++)
{
lstValue = dtListItem.Rows[i]["Value"].ToString();
lstID = dtListItem.Rows[i]["ID"].ToString();
lstItem = new ListItem("<a href=\"javascript:void(0)\" id=\"s5\" style=\"text-decoration:none;color:Black; \" onclick=\"getSelectedItem(' " + lstValue + "','" + i + "','" + lstID + "','anchor');\">" + lstValue + "</a>", dtListItem.Rows[i]["ID"].ToString());
lstItem.Attributes.Add("onclick", "getSelectedItem('" + lstValue + "','" + i + "','" + lstID + "','listItem');");
chkBxLst.Items.Add(lstItem);
}
System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.ID = "divChkList";
div.Controls.Add(chkBxLst);
div.Style.Add("border", "black 1px solid");
div.Style.Add("width", "160px");
div.Style.Add("height", "180px");
div.Style.Add("overflow", "AUTO");
div.Style.Add("display", "none");
ppl.Controls.Add(ddl);
ppl.Controls.Add(div);
if (chkBxLst.SelectedIndex == 1)
{
}
}
public DataTable GetListItem()
{
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Value", typeof(string));
table.Rows.Add(1, "all");
table.Rows.Add(2, "ListItem2");
table.Rows.Add(3, "ListItem3");
table.Rows.Add(8, "ListItem8");
return table;
}
}
please give me a solution for this ....
Reply
Answers (
1
)
regarding intelligence in visual studio
Crystal Report