CheckBox Checked=false when checked in DataList

Discussion in 'ASP .Net' started by yurps, Jan 28, 2005.

  1. yurps

    yurps Guest

    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?
     
    yurps, Jan 28, 2005
    #1
    1. Advertising

  2. yurps

    rajeshthangarasu1983

    Joined:
    Jan 21, 2008
    Messages:
    1
    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
     
    rajeshthangarasu1983, Feb 29, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mehul
    Replies:
    0
    Views:
    780
    mehul
    May 3, 2004
  2. Eric via .NET 247

    [ASP.net / C#] Checkbox Checked Always false

    Eric via .NET 247, Mar 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    9,391
    dunshRB
    Mar 25, 2005
  3. VB Programmer
    Replies:
    1
    Views:
    4,453
    Ken Cox [Microsoft MVP]
    Apr 13, 2005
  4. Replies:
    1
    Views:
    463
  5. randy
    Replies:
    13
    Views:
    461
    Tad McClellan
    Nov 1, 2003
Loading...

Share This Page