Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
i have a gridview that get all of the bounceback emails i add a checkbox on the gridview and here's my code for the gridview
<pre><asp:GridView ID="GridView1" runat="server" ShowHeaderWhenEmpty="true" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"  CellPadding="7" OnRowCommand="GridView1_RowCommand" >
            <HeaderStyle Width="10%" />
            <Columns>
                <asp:TemplateField HeaderText="Read ">
                    <ItemTemplate>
                       <asp:CheckBox runat="server" ID="CheckBoxRead" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="DateCreated" HeaderText="Date and Time" ItemStyle-Width="50%" ItemStyle-Wrap="false"  />
                <asp:BoundField DataField="ErrorTwo" HeaderText="Error" ItemStyle-Width="50%" ItemStyle-Wrap="false"  />
                <asp:TemplateField HeaderText="Receiver">
                    <ItemTemplate>
                       <asp:LinkButton runat="server" CommandArgument='<%# Eval("Sender") %>' Text='<%# Eval("Sender") %>'></asp:LinkButton> <%--OnClientClick="document.getElementById('id01').style.display='block'; return false"--%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Subject" HeaderText="Email Error" ItemStyle-Width="50%" ItemStyle-Wrap="false"  />
                
                <asp:TemplateField HeaderText="Email Body">
                    <ItemTemplate>
                       <asp:Button ID="txtItemBody"  runat="server" Text='<%# Eval("EmailHeader") %>' Width="100px" Enabled="false"/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="View Email ">
                    <ItemTemplate>
                       <asp:Button runat="server"  CommandName="Select" CommandArgument="<%# Container.DataItemIndex %>" Text="View Email" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
</asp:GridView>


What I have tried:

and also i add
<meta http-equiv="Refresh" content="60" />


to automatically refresh the page and to get all of the new data and my problem is how to set the checkbox to remain on the form, also i set a postback on the server side. anyone help me with my code thanks
Posted
Updated 18-Feb-18 23:42pm
Comments
Richard Deeming 16-Feb-18 12:53pm    
The checkboxes will not "disappear". Did you mean to say that you want to keep the checked state when the page reloads?
Member 13427032 16-Feb-18 12:58pm    
yes sir the check will remain on the checkbox. can you help me with my code?
ZurdoDev 16-Feb-18 13:19pm    
Who is checking the box? The user? The code? What does it mean?

Why not save that to the database so that when the page reloads the checkbox will be checked.
Member 13427032 16-Feb-18 13:23pm    
the user will check the box. i did not save on the DB because im getting the data on the EWS. The objective of this project to get all of the bounce back emails and in order to determine the read emails i add the checkbox but every time the page reload the check on the checkbox disappear. thanks for the reply
F-ES Sitecore 19-Feb-18 4:43am    
asp.net controls only remember their state if you do a page postback, ie push a button etc as that causes a form submission which passes all the info .net needs to re-create your controls. If you simply reload the page then you start from scratch and .net doesn't know what boxes were checked.

When the users check the boxes you'll need to store the ids if the boxes in a cookie using javascript, and when the page loads look at the ids in the cookie and pre-select the relevant check boxes.

1 solution

Using J-query you can maintain the state of the check box.

Take a hidden field and set this hidden field value to 1 ,if user checks the check box and 0 if user unchecked the checkbox
Now on document.ready function check the hidden-field value and check/unchecked the checkbox accordingly.

Regards
Sarita Singh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900