![]() |
Desktop Development »
Miscellaneous »
General
Intermediate
License: The Code Project Open License (CPOL)
How to Get the CheckBoxlist Value using JavaScript?By Trilochan Nayak.I am using checkboxlist in ASP.NET 2.0 C#.I bind a list of records in checklistbox from DB. I could not get the value from JavaScript. |
C# (C#2.0), Javascript, Windows, .NET (.NET2.0), Visual-Studio, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
We have to update the checkboxlist into a new control say name:"CheckBoxListExCtrl" which can inherit checkboxlist property.
CheckBoxList extension.
Create a new control by the following steps.
Create a class library project:
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CheckBoxListExCtrl
{
public class CheckBoxListExCtrl :CheckBoxList, IRepeatInfoUser
{
void IRepeatInfoUser.RenderItem(ListItemType itemType,
int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
writer.WriteBeginTag("input");
writer.WriteAttribute("type", "checkbox");
writer.WriteAttribute("name", UniqueID);
writer.WriteAttribute("id", ClientID + "_" +
repeatIndex.ToString(NumberFormatInfo.InvariantInfo));
writer.WriteAttribute("value", Items[repeatIndex].Value);
System.Web.UI.AttributeCollection attrs = Items[repeatIndex].Attributes;
foreach (string key in attrs.Keys)
{
writer.WriteAttribute(key, attrs[key]);
}
writer.Write(">");
writer.Write(Items[repeatIndex].Text);
}
}
}
Build it into a *.dll file,and add it to toolbox of VS.NET. Then you can use it from your project.
When we add this control into *.aspx page, the& following code is generated.
<checkboxlistexctrl id="CheckBoxListExCtrl1" runat="server"></checkboxlistexctrl>
From the code behind, we have to write code to bind the CheckBoxListExCtrl control.
protected void PopulateCheckBoxListExCtrl()
{
CheckBoxListExCtrl.DataSource = DtRecords;//DataTable DtRecords from DB
CheckBoxListExCtrl.DataTextField ="Column1";
CheckBoxListExCtrl.DataValueField ="Column2";
CheckBoxListExCtrl.DataBind();
}
Then we can get the checkbox list value easily by:
document.getElementByID("CheckBoxListExCtrl").value
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 18 Sep 2007 Editor: Deeksha Shenoy |
Copyright 2007 by Trilochan Nayak. Everything else Copyright © CodeProject, 1999-2010 Web21 | Advertise on the Code Project |