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. Advertisements

  2. yurps

    rajeshthangarasu1983

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

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:
    900
    mehul
    May 3, 2004
  2. Nevyn Twyll
    Replies:
    8
    Views:
    2,324
  3. 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,605
    dunshRB
    Mar 25, 2005
  4. VB Programmer
    Replies:
    1
    Views:
    4,676
    Ken Cox [Microsoft MVP]
    Apr 13, 2005
  5. André
    Replies:
    3
    Views:
    1,977
  6. Replies:
    1
    Views:
    564
  7. Derek Pettinato

    Treeview Checked Item = False when it is True

    Derek Pettinato, Nov 5, 2003, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    652
  8. randy
    Replies:
    13
    Views:
    769
    Tad McClellan
    Nov 1, 2003
Loading...