如何在第二页gridview中维护值 [英] How to maintain the values in the second page gridview
本文介绍了如何在第二页gridview中维护值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到错误.
Hi,
I am getting below error.
"Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request."
当我移至gridview的下一页时,我正在选择该行中的某行.
基于此,我正在选择下拉值进行编辑..
但是,当我选择下拉菜单时,出现上述错误...?
什么是错误.???
如何在第二页gridview中维护值... ??
查看我的代码
-----------
ASPX代码
---------
When i move to next page in the gridview, i am selecting some row in the row.
Based on that, i am selecting dropdown values for editing..?
But, when i select the dropdown i am getting the above error...?
What is the error.???
How to maintain the values in the second page gridview...??
See my code
-----------
ASPX Code
---------
<asp:GridView ID="GridView1" runat="server" align="center" AllowPaging="true" DataKeyNames="PrNo,RevisionNo"
AutoGenerateColumns="False" class="tabulardata"
HorizontalAlign="Center" Width="100%">
<columns>
<asp:TemplateField HeaderText="Sl.No" ItemStyle-HorizontalAlign="Center"
ItemStyle-Width="4%">
<itemtemplate>
<%# Container.DataItemIndex + 1%>
</itemtemplate>
<%-- <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="PrNo" Visible="true" DataField="PrNo"
ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="PrNo">
<itemstyle horizontalalign="Center" width="15%" />
<asp:TemplateField HeaderText="PrNo" Visible="false" HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="10%">
<itemtemplate>
<asp:Label ID="lblPrNo" runat="server" Text='<%# Eval("PrNo") %>'>
</itemtemplate>
<HeaderStyle HorizontalAlign="Center" />
<asp:BoundField HeaderText="RevisionNo" Visible="true" DataField="RevisionNo"
ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="RevisionNo">
<itemstyle horizontalalign="Center" width="10%" />
<asp:TemplateField HeaderText="RevisionNo" Visible="false" HeaderStyle-HorizontalAlign="Center" >
<itemtemplate>
<asp:Label ID="lblRevisionNo" runat="server" Text='<%# Eval("RevisionNo") %>'>
</itemtemplate>
<HeaderStyle HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:HyperLink ID="hyperlink1" onclick="" BorderStyle="None" runat="server" Height="15"
ImageUrl="~/images/EditImage.png"
Width="50%" >
</itemtemplate>
<itemstyle horizontalalign="Center" width="6%" />
<asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" Height="20"
ImageUrl="~/images/DeleteImage.png" OnClientClick="return confirm('Are you sure you want to delete this PR Number.?');"
CommandArgument='<%# container.DisplayIndex%>'
Width="20" />
</itemtemplate>
<itemstyle horizontalalign="Center" width="2%" />
</columns>
<alternatingrowstyle backcolor="#DDDDFF" />
ASPX.VB代码
------------
ASPX.VB Code
------------
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
Try
If e.CommandName = "Delete" Then
Dim RowNo As Integer = Convert.ToInt32(e.CommandArgument)
Dim PrNo As String = GridView1.DataKeys(RowNo)("PrNo").ToString()
Dim RevisionNo As String = GridView1.DataKeys(RowNo)("RevisionNo").ToString()
'Delete the record
If PrNo.ToString IsNot Nothing Then
Conn.Open()
Qry = ""
Qry = "DELETE FROM PMT_PR WHERE PrNo='" & PrNo & "' and RevisionNo='" & RevisionNo & "'"
Cmd.Connection = Conn
Cmd.CommandText = Qry
Cmd.ExecuteNonQuery()
Conn.Close()
End If
FillGrid()
End If
'Session("Mode") = ""
LblMessage.Visible = True
LblMessage.Text = "PR No. Deleted"
Catch ex As Exception
WriteLogFile(Me.[GetType]().Name, "GridView1_RowCommand()", ex.Message.ToString())
End Try
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
'for Edit the PR Details to pass the PRNo and RevisionNo in the URL
Dim Hyper1 As New HyperLink
If e.Row.RowType = DataControlRowType.DataRow Then
Hyper1 = e.Row.FindControl("hyperlink1")
Dim PNo1 As Integer = e.Row.Cells(1).Text.ToString
Dim RevNo1 As Integer = e.Row.Cells(3).Text.ToString
Hyper1.NavigateUrl = "PR.aspx?PNo=" & e.Row.Cells(1).Text & "&RevNo=" & e.Row.Cells(3).Text & "&page=" & GridView1.PageIndex + 1
Hyper1.DataBind()
End If
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
ResetFormControlValues(Me)
LblMessage.Text = "PR Number Deleted"
End Sub
Protected Sub drpRevNo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles drpRevNo.SelectedIndexChanged
If Session("Mode") = "E" Or Session("Mode") = "N" Then
If RecordExists() = False Then
Dim myscript As String = "alert('Revision Number Already Selected. Select another Revision No.!');"
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "myscript", myscript, True)
drpRevNo.Focus()
txtChangeRevNo.ReadOnly = True
Exit Sub
End If
End If
End Sub
Function RecordExists() As Boolean
Dim ExistFlg As Boolean
ExistFlg = True
Conn.Open()
Qry = ""
Qry = "select * from PMT_PR where PrNo='" & txtPRNo.Text & "' and RevisionNo='" & drpRevNo.SelectedValue & "'"
Cmd.Connection = Conn
Cmd.CommandText = Qry
Rdr = Cmd.ExecuteReader
If Rdr.HasRows Then
While Rdr.Read
ExistFlg = False
Exit While
End While
End If
Rdr.Close()
Conn.Close()
Return ExistFlg
'End If
End Function
推荐答案
阅读此内容
无法加载viewstate吗?典型问题,有明显的解决方案 [ ^ ]
Read this
Failed to load viewstate ? Typical problem, with an obvious solution[^]
这篇关于如何在第二页gridview中维护值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文