0

How to automatic store value in database when checkbox is checked and refresh my To do list. Here is my code:

This is my HTML:

<asp:Repeater ID="rpTodos" runat="server">
    <ItemTemplate>
           <tr>
                <td><%# Eval("TodosID", "{0:d}") %></td>             
                <td><%# Eval("TaskName", "{0:d}") %></td>
                <td><asp:CheckBox ID="cbisdone" runat="server" AutoPostBack="true" checked='<%#Eval("IsDone")%>'></asp:CheckBox></td>                                                                                                       
               <td><%# Eval("TaskDate", "{0:d}") %></td>                                        
            </tr>                                            
    </ItemTemplate>                                        
</asp:Repeater>

This is code behind:

var todos2 = ctx.Todos.ToList().Where(t=> t.IsDone == false).ToList();
rpTodos.DataSource = todos2;
rpTodos.DataBind();
1

1 Answer 1

1

Add a OnCheckedChanged event in your aspx page.

<asp:CheckBox ID="cbisdone" runat="server" AutoPostBack="true" checked='<%#Eval("IsDone")%>' OnCheckedChanged="cbisdone_changed"></asp:CheckBox>

Create a new event that would listen to raised event and cast the sender object back to Checkbox.

protected void cbisdone_changed(object sender, EventArgs e)
{
    if (sender != null)
    {
        if (((CheckBox)sender).Checked)
        {
              // Update the status in DB.
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.