本文介绍了即使我访问了GridView中的任何页面,如何维护所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我转到gridview的下一页时,先前的值(如复选框值和文本框值)将被清除.
即使访问任何页面,我也希望保留所有值.
有什么问题以及如何维护值...?
看看我的代码.
------------
ASPX代码
----------
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代码
-------------
ASPX.VB Code
-------------
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
推荐答案
这篇关于即使我访问了GridView中的任何页面,如何维护所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!