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
Hazel Mahmud
1.4k
315
69.8k
add checkbox in dropdowlist asp .net c#
Apr 30 2015 12:09 AM
i have below code from a website that display image in dropdownlist but how do i add a code that also add check box in the dropdownlist. please anyone help me. Tq so much.
namespace
ProjectDemo_Asp.et
{
public
partial
class
ddlitemwithicon
: System.Web.UI.
Page
{
protected
void
Page_Load(
object
sender,
EventArgs
e)
{
// if (!IsPostBack)
{
DataTable
objdt =
new
DataTable
();
objdt = GetDataForChart();
DropDownList1.DataSource = objdt;
DropDownList1.DataTextField =
"Country"
;
DropDownList1.DataValueField =
"Id"
;
DropDownList1.DataBind();
//Now add class to each and every item in dropdown
//Now, add a "SysCode" attribute to each item in the dropdown list
string
imageURL =
""
;
for
(
int
i = 0; i < DropDownList1.Items.Count; i++)
{
switch
(DropDownList1.Items[i].Text)
{
case
"India"
: imageURL =
"Images/flag-of-India.png"
;
break
;
case
"Kuwait"
: imageURL =
"Images/flag-of-Kuwait.png"
;
break
;
case
"Egypt"
: imageURL =
"Images/flag-of-Egypt.png"
;
break
;
case
"Bangladesh"
: imageURL =
"Images/flag-of-Bangladesh.png"
;
break
;
case
"Afghanistan"
: imageURL =
"Images/flag-of-Afghanistan.png"
;
break
;
}
ListItem
item = DropDownList1.Items[i];
item.Attributes[
"style"
] =
"background: url("
+ imageURL +
");background-repeat:no-repeat;"
;
}
}
}
///
This method will provide data
///
In this methos you can fatch data from DB and pass it to chart control
///
public
DataTable
GetDataForChart()
{
DataTable
_objdt =
new
DataTable
();
_objdt.Columns.Add(
"Country"
,
typeof
(
string
));
_objdt.Columns.Add(
"Id"
,
typeof
(
long
));
_objdt.Columns.Add(
"LabelValue"
);
var
_objrow = _objdt.NewRow();
_objrow[
"Country"
] =
"India"
;
_objrow[
"Id"
] = 1;
_objdt.Rows.Add(_objrow);
_objrow = _objdt.NewRow();
_objrow[
"Country"
] =
"Kuwait"
;
_objrow[
"Id"
] = 2;
_objdt.Rows.Add(_objrow);
_objrow = _objdt.NewRow();
_objrow[
"Country"
] =
"Egypt"
;
_objrow[
"Id"
] = 3;
_objdt.Rows.Add(_objrow);
_objrow = _objdt.NewRow();
_objrow[
"Country"
] =
"Bangladesh"
;
_objrow[
"Id"
] = 4;
_objdt.Rows.Add(_objrow);
_objrow = _objdt.NewRow();
_objrow[
"Country"
] =
"Afghanistan"
;
_objrow[
"Id"
] = 5;
_objdt.Rows.Add(_objrow);
return
_objdt;
}
}
}
Reply
Answers (
2
)
Can I show this in c#
How To set page size in code for print rdlc report using c#.