i've read that this code should set the text and value of list item by using the overloaded Add() method:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string[] Genre = {"SciFi", "Novels", "Computers", "History", "Religion"};
string[] Code = {"sf", "nvl", "cmp", "his", "rel"};for(int i = 0; i < Genre.GetLength(0); i++)
{
cblGenre.Items.Add(new ListItem(Genre[i],Code[i]));
}
}
it builds with no problem, but when i view the source of the actual page it creates in the browser, the ListItems have neither a text or a value attribute. what's up with that?It works fine with me. When I try your code, and then have a look at the source of the generated html page, I get:
<select name="cblGenre" id="cblGenre">
<option value="sf">SciFi</option>
<option value="nvl">Novels</option>
<option value="cmp">Computers</option>
<option value="his">History</option>
<option value="rel">Religion</option>
which is correct. What do you get?
Hi,
Your code is working fine with me.
I got output as below :
<select name="cblGenre" size="4" id="cblGenre" style="width:432px;Z-INDEX: 102; LEFT: 149px; POSITION: absolute; TOP: 209px">
<option value="sf">SciFi</option>
<option value="nvl">Novels</option>
<option value="cmp">Computers</option>
<option value="his">History</option>
<option value="rel">Religion</option>
</select>
here's what i do:
i click f5 to build the stuff, and a browser windows pops up. the markup i get looks like this:
<table id="cblGenre" cellspacing="10" cellpadding="5" border="0">
<tr>
<td>
<input id="cblGenre_0" type="checkbox" name="cblGenre:0" onclick="__doPostBack('cblGenre$0','')" language="javascript" /><label for="cblGenre_0">SciFi</label>
</td>
<td>
<input id="cblGenre_2" type="checkbox" name="cblGenre:2" onclick="__doPostBack('cblGenre$2','')" language="javascript" /><label for="cblGenre_2">Computers</label>
</td>
<td>
<input id="cblGenre_4" type="checkbox" name="cblGenre:4" onclick="__doPostBack('cblGenre$4','')" language="javascript" /><label for="cblGenre_4">Religion</label>
</td>
</tr>
<tr>
<td>
<input id="cblGenre_1" type="checkbox" name="cblGenre:1" onclick="__doPostBack('cblGenre$1','')" language="javascript" /><label for="cblGenre_1">Novels</label>
</td>
<td>
<input id="cblGenre_3" type="checkbox" name="cblGenre:3" onclick="__doPostBack('cblGenre$3','')" language="javascript" /><label for="cblGenre_3">History</label>
</td>
</tr>
</table
why is mine all crazy?
What is the control cblGenre is it a Dropdownlist/ListBox?
It seems like you have a checkboxlist or control related to checkbox?
it's a CheckBoxList.
Since its a checkboxList and i guess in your case with AutoPostBack Property set to true
You'll get O/P of the source in the same manner as you are getting it
im sorry, what's O/P?
O/P->Output
0 comments:
Post a Comment