CheckBox Checked=false when checked in DataList

Y

yurps

Hello I have a DataList like this

<asp:DataList id="Questions" Runat="server">
<ItemTemplate>
<table border="1">
<tr>
<td>
<asp:CheckBox ID="Yes" Runat="server"></asp:CheckBox>
<input type="hidden" runat="server" value='<%#
DataBinder.Eval(Container.DataItem, "I_QUESTION_ID") %>' ></input>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "V_HEALTH_QUESTION")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:Button id="DoThis" runat="server" text="go"></asp:Button>

in the click for the button I do this
StringBuilder hqs = new StringBuilder();
foreach(DataListItem dli in Questions.Items)
{
//if ( ((CheckBox)dli.Controls[1]).Checked )
if ( ((CheckBox)dli.FindControl("Yes")).Checked )
hqs.Append( ((HtmlInputHidden)dli.Controls[3]).Value+",");
}

The first item says checked=false even when I checked it.....
Any items?
 
Joined
Jan 21, 2008
Messages
1
Reaction score
0
Solution To checkbox checked=false in datalist

Bind the data when page.ispostback is false

if( ! page.ispostback)
{
bindyourdata();
}


Comment:The problem why checkbox is showing checked status false is when u press the button, page post back occurs and datalist is populated again. So bind the data when page.ispostback is false
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top