Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

When i go to next page in the gridview, the previous values such as checkbox values and Textbox values are cleared.

I want to maintain all the values even if i visited any pages.

What is the problem and how to maintain the values...?

see my code.
------------
ASPX Code
----------
<asp:GridView ID="GridView1" runat="server" align="center" AllowPaging="True"
                                AutoGenerateColumns="False" class="tabulardata" DataSourceID="SqlDataSource1"
                                HorizontalAlign="Center" Width="100%" OnRowCommand="GridView1_RowCommand"
                                OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting">
                                <columns>
                                    <asp:TemplateField HeaderText="Sl.No" ItemStyle-HorizontalAlign="Center"
                                        ItemStyle-Width="4%">
                                        <itemtemplate>
                                            <asp:Label ID="Sno" runat="server">
                                        </itemtemplate>
                                        <itemstyle horizontalalign="Center" />

                                   <asp:TemplateField HeaderText="CheckAll">
                                       <HeaderTemplate>
                                           <asp:CheckBox ID="chkSelectAll" runat="server" AutoPostBack="true" OnCheckedChanged="chkSelectAll_CheckedChanged"/>
                                       </HeaderTemplate>
                                       <itemtemplate>
                                               <asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true" OnCheckedChanged="chkSelect_CheckedChanged"/>
                                       </itemtemplate>

                                    <asp:BoundField HeaderText="Department" Visible="true" DataField="Department"
                                        ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="Department">
                                        <itemstyle horizontalalign="Center" width="20%" />

                                     <asp:BoundField HeaderText="Cost Centre" Visible="true" DataField="CostCentre"
                                        ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="CostCentre">
                                        <itemstyle horizontalalign="Center" width="20%" />

                                     <asp:BoundField HeaderText="Work Service Code" DataField="WorkServiceCode"
                                        ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="WorkServiceCode">
                                        <itemstyle horizontalalign="Center" width="30%" />

                                     <asp:BoundField HeaderText="Prof.Role Family ID" DataField="ProfRoleFamilyID"
                                        ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="ProfRoleFamilyID">
                                        <itemstyle horizontalalign="Center" width="28%" />

                                     <asp:TemplateField HeaderText="Budget ManHours"  ItemStyle-Width="65%">
                                       <itemtemplate>
                                               <asp:TextBox ID="txtManHours" runat="server" ForeColor="Blue"  Width="75%" ReadOnly="true">
                                       </itemtemplate>
                                        <itemstyle horizontalalign="Center" />

                                </columns>
                                <alternatingrowstyle backcolor="#FFF5F5" />



ASPX.VB Code
-------------
VB
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
      Dim sno As New Label
      Dim SrNo As Integer
      If e.Row.RowType = DataControlRowType.DataRow Then
          SrNo = (GridView1.PageIndex + 1) * 10 - 9
          sno = e.Row.FindControl("Sno")
          sno.Text = e.Row.RowIndex + SrNo
          sno.DataBind()
      End If
      'Dim chkNewActive As CheckBox = DirectCast(GridView1.FooterRow.FindControl("chkNewActive"), CheckBox)
  End Sub
  Protected Sub chkSelect_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
      Dim chkTest As CheckBox = DirectCast(sender, CheckBox)
      Dim grdRow As GridViewRow = DirectCast(chkTest.NamingContainer, GridViewRow)
      Dim txtMHrs As TextBox = DirectCast(grdRow.FindControl("txtManHours"), TextBox)
      'Dim txtlocation As TextBox = DirectCast(grdRow.FindControl("txtLocation"), TextBox)
      If chkTest.Checked Then
          txtMHrs.[ReadOnly] = False
          txtMHrs.ForeColor = System.Drawing.Color.Black
      Else
          txtMHrs.[ReadOnly] = True
          txtMHrs.ForeColor = System.Drawing.Color.Blue
      End If
  End Sub

  Protected Sub chkSelectAll_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
      Dim chkAll As CheckBox = DirectCast(GridView1.HeaderRow.FindControl("chkSelectAll"), CheckBox)
      If chkAll.Checked = True Then
          For Each gvRow As GridViewRow In GridView1.Rows
              Dim chkSel As CheckBox = DirectCast(gvRow.FindControl("chkSelect"), CheckBox)
              chkSel.Checked = True
              Dim txtMHrs As TextBox = DirectCast(gvRow.FindControl("txtManHours"), TextBox)
              txtMHrs.[ReadOnly] = False
              txtMHrs.ForeColor = System.Drawing.Color.Black
          Next
      Else
          For Each gvRow As GridViewRow In GridView1.Rows
              Dim chkSel As CheckBox = DirectCast(gvRow.FindControl("chkSelect"), CheckBox)
              chkSel.Checked = False
              Dim txtMHrs As TextBox = DirectCast(gvRow.FindControl("txtManHours"), TextBox)
              txtMHrs.[ReadOnly] = True
              txtMHrs.ForeColor = System.Drawing.Color.Blue
          Next
      End If
  End Sub
Posted
Updated 22-Jul-11 11:49am
v2
Comments
gani7787 22-Jul-11 10:09am    
Any help pls.

1 solution

 
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