c# - Dynamic Checkboxlist in repeater, ASP.NET -
i have checkboxlist
in repeater
, code have here dynamic dropdownlist in repeater, asp.net.
if this:
<asp:checkboxlist id="chklworktype" runat="server" ondatabinding="chklworktype_databinding"></asp:checkboxlist> protected void chklworktype_databinding(object sender, system.eventargs e) { checkboxlist chk = (checkboxlist)(sender); chk.items.add(new listitem("nem 1", "1")); chk.items.add(new listitem("num 2", "2")); chk.selectedvalue = chk.datavaluefield; }
this error message:
system.argumentoutofrangeexception: 'chklworktype' has selectedvalue invalid because not exist in list of items.
datavaluefield
gets or sets field of data source provides value of each list item. name of column or that. using name selectedvalue
doesn't exist because haven't assingned one, it's string.empty
.
you use this, if want first item selected:
chk.selectedvalue = "1";
that's value of first listitem
(new listitem("nem 1", "1")
).
of course use selectedindex
:
chk.selectedindex = 0;
Comments
Post a Comment