locked
Error-Failed to load viewstate. I am using 2 gridview. RRS feed

  • Question

  • User390265149 posted

    I am using 2 gridview.

    One gridview display list of employees and

    other gridview is used for entry of education qualifications.

    My application works successfully for displaying records of education qualification of employees.

    When I click on an one employee in 1st gridview, it displays qualifications in 2nd gridview.

    The problem occurs when I save qualification of 1 employee and display successful message in another form and then return to same form for entry of 2nd employee, it gives above mentioned error.

    I have to run program every time for entry of qualifications of each employee. Presently my program is in developmental stage and I am checking my program for every data entry.

    Note: This error comes after saving qualifications of any 1 employee and after clicking any command button.

    Please consider my problem.

    Monday, October 17, 2016 3:10 PM

Answers

  • User-691209617 posted

    You have code in you Page_Load event so add this 

    if (!Page.IsPostBack)
    { //do something }

    This error is thrown when you click on your command and the Page_load is being ran again, in a normal life cycle will be Page_Load -> Click on Command -> Page_Load (again) -> Process ItemCommand Event.

    Also, add this

    <%@ Page EnableEventValidation="false" %>

    Hope it helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 18, 2016 3:02 PM

All replies

  • User-691209617 posted

    One Simple solution for said problem is 

    EnableViewState="false"



    If above solution not works then I would suspect that the 

    ViewState  error is being caused by code on the code-behind and is not being triggered by the GridView. Can your post the code-behind for your 
    OnRow...methods and any Page_Load / Page_Init  code?
    Monday, October 17, 2016 3:22 PM
  • User390265149 posted

    I added EnableViewState="false" in following line

    <%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PersonQualificationDetail.aspx.vb" EnableViewState="false" Inherits="PersonQualificationDetail" %>

    After then on every clicking I am getting following error message.

    Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

    Tuesday, October 18, 2016 1:58 PM
  • User390265149 posted

    I am giving my code as below

    <%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PersonQualificationDetail.aspx.vb" EnableViewState="false" Inherits="PersonQualificationDetail" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
         <script type = "text/javascript">
             function Confirm() 
             {
                 var confirm_value = document.createElement("INPUT");
                 confirm_value.type = "hidden";
                 confirm_value.name = "confirm_value";
                 if (confirm("क्या आप इस क्वालिफिकेशन को डिलीट करना चाहते हैं?")) 
                 {
                     confirm_value.value = "हाँ";
                 }
                 else 
                 {
                     confirm_value.value = "नहीं";
                 }
                 document.forms[0].appendChild(confirm_value);
             }
        </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
        <table style="width:100%">
          <tr>
            <td colspan="2"><center><h1>व्यक्ति का एजुकेशनल क्वालिफिकेशन</h1></center></td>
          </tr>
          <tr>
            <td>
              <table>
                <tr>
                  <td>
                    <asp:Label ID="EmployeeIDLabel" runat="server" Text=""></asp:Label>
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" AppendDataBoundItems="true" TabIndex="1" Width="200px" Height="20px">
                    </asp:DropDownList>
                  </td>
                </tr>
                <tr>
                  <td>
                    <asp:Label ID="PagingLabel" runat="server" Text="पेजिंग सुचना" Enabled="False" ></asp:Label>
                    <asp:DropDownList ID="PageList" runat="server" AutoPostBack="true" Enabled="false" TabIndex="2" Width="100px">
                    </asp:DropDownList>
                    <asp:CheckBox ID="PagewiseCheckBox" runat="server" Text="पेज के हिसाब से" AutoPostBack="true" Enabled="false" TabIndex="3" />
                  </td>
                </tr>
                <tr>
                  <td>
                    <hr />
                    <asp:Label ID="GridViewTitleLabel" runat="server" Font-Bold="true"></asp:Label>
                    <table cellpadding="1px" cellspacing="1px" >
                      <tr>
                        <td><asp:Label ID="Label1" runat="server" CssClass="HeaderStyle" Text="क्र.सं." Width="35px"></asp:Label></td>
                        <td><asp:Label ID="Label2" runat="server" CssClass="HeaderStyle" Text="कोड" Width="60px"></asp:Label></td>
                        <td><asp:Label ID="Label3" runat="server" CssClass="HeaderStyle" Text="नाम " Width="125px"></asp:Label></td>
                        <td><asp:Label ID="Label6" runat="server" CssClass="HeaderStyle" Text="जन्मदिन" Width="50px"></asp:Label></td>
                        <td><asp:Label ID="Label9" runat="server" ForeColor="White" Width="15px"></asp:Label></td>
                      </tr>
                    </table>
                    <asp:Panel ID="Panel1" runat="server" ScrollBars="Vertical" Height="265">
                      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" PageSize="15" Font-Size="Smaller"
                                DataKeyNames="em_employeeid" RowStyle-VerticalAlign="Bottom" ShowHeader="false" OnRowCreated="GridView1_RowCreated">
                        <Columns>
                          <asp:TemplateField ItemStyle-Width="35px" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                              <%# Container.DataItemIndex + 1%>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:ButtonField ButtonType="Link" DataTextField="em_employeeid" HeaderText="Employee ID" ItemStyle-Width="60px" ItemStyle-HorizontalAlign="Center" />
                          <asp:BoundField DataField="em_empname" HeaderText="Employee Name" ItemStyle-Width="125px" ItemStyle-HorizontalAlign="Left" />
                          <asp:BoundField DataField="em_birthdate" HeaderText="Date of Birth" ItemStyle-Width="50px" DataFormatString="{0:dd-MM-yyyy}" HtmlEncode="false" ItemStyle-HorizontalAlign="Left" />
                        </Columns>
                      </asp:GridView>
                    </asp:Panel>
                  </td>
                </tr>
              </table>
            </td>
    
            <td>
              <table>
                <tr>
                  <td>
                    <table>
                      <tr>
                        <td>
                          <table>
                            <tr>
                              <td>
                                <asp:Label ID="NameLabel" runat="server" Text="नाम" Width="90px"></asp:Label>
                              </td>
                              <td>:</td>
                              <td class="EditText">
                                <asp:Label ID="NameTextLabel" runat="server" Width="400px"></asp:Label>
                              </td>
                            </tr>
                          </table>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
                <tr>
                  <td>
                    <asp:Label ID="Label4" runat="server" Font-Bold="true"></asp:Label>
                    <table cellpadding="1px" cellspacing="1px" >
                      <tr>
                        <td><asp:Label ID="Label18" runat="server" CssClass="HeaderStyle" Text="क्र.सं." Width="30px"></asp:Label></td>
                        <td><asp:Label ID="Label5" runat="server" CssClass="HeaderStyle" Text="से" Width="20px"></asp:Label></td>
                        <td><asp:Label ID="Label17" runat="server" CssClass="HeaderStyle" Text="चेंज" Width="40px"></asp:Label></td>
                        <td><asp:Label ID="Label7" runat="server" CssClass="HeaderStyle" Text="एजुकेशनल क्वालिफिकेशन" Width="150px"></asp:Label></td>
                        <td><asp:Label ID="Label8" runat="server" CssClass="HeaderStyle" Text="अन्य क्वालिफिकेशन" Width="150px"></asp:Label></td>
                        <td><asp:Label ID="Label10" runat="server" CssClass="HeaderStyle" Text="स्ट्रीम/सब्जेक्ट" Width="105px"></asp:Label></td>
                        <td><asp:Label ID="Label13" runat="server" CssClass="HeaderStyle" Text="बोर्ड/यूनिवर्सिटी" Width="175px"></asp:Label></td>
                        <td><asp:Label ID="Label14" runat="server" CssClass="HeaderStyle" Text="स्कूल/कॉलेज" Width="150px"></asp:Label></td>
                        <td><asp:Label ID="Label15" runat="server" CssClass="HeaderStyle" Text="पासिंग ईयर" Width="70px"></asp:Label></td>
                        <td><asp:Label ID="Label16" runat="server" CssClass="HeaderStyle" Text="परसेंटेज" Width="40px"></asp:Label></td>
                        <td><asp:Label ID="Label12" runat="server" CssClass="HeaderStyle" Text="डिलीट" Width="40px"></asp:Label></td>
                        <td><asp:Label ID="Label11" runat="server" ForeColor="White" Width="15px"></asp:Label></td>
                      </tr>
                    </table>
                    <asp:Panel ID="Panel2" runat="server" ScrollBars="Vertical" Height="150px">
                      <asp:GridView ID="QualificationGridView" runat="server" AutoGenerateColumns="false" ShowHeader="false" 
                                      RowStyle-VerticalAlign="Bottom" OnRowCreated="QualificationGridView_RowCreated" >
                        <Columns>
                          <asp:TemplateField ItemStyle-Width="30px" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                              <%# Container.DataItemIndex + 1%>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="Select" ItemStyle-Width="20px">
                            <ItemTemplate>
                              <center>
                                <asp:CheckBox ID="SelectCheckBox" runat="server" OnCheckedChanged="SelectCheckBox_CheckedChanged" AutoPostBack="true" TabIndex="4" />
                              </center>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="EditCommand" ItemStyle-Width="40px">
                            <ItemTemplate>
                              <center>
                                <asp:Button ID="EditButton" runat="server" CommandName="Edit" Width="40px" Text="Edit" CommandArgument="<%# Container.DataItemIndex %>" />
                              </center>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="Education Qualification" ItemStyle-Width="150px">
                            <ItemTemplate>
                              <asp:DropDownList ID="QualificationDropDownList" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
                                                OnSelectedIndexChanged="QualificationDropDownList_SelectedIndexChanged" TabIndex="5" Width="145px">
                              </asp:DropDownList>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="Other Qualification" ItemStyle-Width="150px" >
                            <ItemTemplate>
                              <asp:TextBox ID="OtherQualificationTextBox" runat="server" CssClass="CapitalText" MaxLength="20" Width="145px" Enabled="false" TabIndex="6"></asp:TextBox>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="Stream/Subjects" ItemStyle-Width="105px" >
                            <ItemTemplate>
                              <asp:TextBox ID="StreamSubjectTextBox" runat="server" CssClass="CapitalText" MaxLength="50" Width="100px" Enabled="false" TabIndex="8"></asp:TextBox>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="University/Board" ItemStyle-Width="175px" >
                            <ItemTemplate>
                              <asp:TextBox ID="UniversityBoardTextBox" runat="server" CssClass="CapitalText" MaxLength="100" Width="170px" Enabled="false" TabIndex="9"></asp:TextBox>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="School/College" ItemStyle-Width="125px" >
                            <ItemTemplate>
                              <asp:TextBox ID="SchoolCollegeTextBox" runat="server" CssClass="CapitalText" MaxLength="100" Width="145px" Enabled="false" TabIndex="10"></asp:TextBox>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="PassingYear" ItemStyle-Width="70px" >
                            <ItemTemplate>
                                <asp:TextBox ID="PassingYearTextBox" runat="server" CssClass="CapitalText" MaxLength="4" Width="67px" Enabled="false" TabIndex="11"></asp:TextBox>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="Percentage" ItemStyle-Width="40px" >
                            <ItemTemplate>
                                <asp:TextBox ID="PercentageTextBox" runat="server" CssClass="CapitalText" MaxLength="10" Width="37px" Enabled="false" TabIndex="12"></asp:TextBox>
                            </ItemTemplate>
                          </asp:TemplateField>
                          <asp:TemplateField HeaderText="DeleteCommand" ItemStyle-Width="40px">
                            <ItemTemplate>
                              <center>
                                <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Width="40px" Text="Del" CommandArgument="<%# Container.DataItemIndex %>" />
                              </center>
                            </ItemTemplate>
                          </asp:TemplateField>
                        </Columns>
                        <HeaderStyle CssClass="HeaderStyle" Height="20px" />
                      </asp:GridView>
                    </asp:Panel>
                  </td>
                </tr>
                <tr>
                  <td colspan="6">
                    <table>
                      <tr>
                        <td colspan="3">
                          <asp:Label ID="MessageLabel" runat="server" Text=""></asp:Label>
                        </td>
                      </tr>
                      <tr>
                        <td colspan="3">
                          <center>
                            <asp:Button ID="SaveButton" runat="server" Text="सेव" Width="80" TabIndex="23" />
                            <asp:Button ID="UpdateButton" runat="server" Text="अपडेट" Width="80" TabIndex="24" />
                            <asp:Button ID="CancelButton" runat="server" Text="कैंसिल" Width="80" TabIndex="25" />
                            <asp:Button ID="BackButton" runat="server" Text="बैक" Width="80" TabIndex="26" />
                          </center>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
    
    </asp:Content>
    
    
    Imports System
    Imports System.Data
    Imports System.Data.OleDb
    Imports WebService
    
    Partial Class PersonQualificationDetail
        Inherits System.Web.UI.Page
    
        Dim strSQL As String
        Dim connString As String = ConfigurationSettings.AppSettings("connection1")
        Dim conn As New OleDbConnection(connString)
        Dim oleDbCommand As New OleDbCommand
        Dim webService As New WebService
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Session("appName") = "PersonQualificationDetail.aspx"
            If Session("userID") = "" Then
                Response.Redirect("Default.aspx")
            Else
                If Not IsPostBack Then
    
                    strSQL = "SELECT COUNT(*) FROM options WHERE firsttime = 'N'"
                    Dim DT As New DataTable
                    Try
                        Dim DA As New OleDbDataAdapter(strSQL, conn)
                        DA.Fill(DT)
                    Catch ex As Exception
                        MessageLabel.CssClass = "ErrorMessage"
                        MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                        Session("message1") = MessageLabel.Text
                        MesgBox()
                    End Try
                    If DT.Rows(0).Item(0) = 1 Then
                        Dim mpLogLabel As Label
                        Dim mpLogButton As Button
    
                        mpLogLabel = CType(Master.FindControl("LogLabel"), Label)
                        If Not mpLogLabel Is Nothing Then
                            mpLogLabel.Text = "Welcome " + Session("UserID").ToString
                        End If
    
                        mpLogButton = CType(Master.FindControl("LogButton"), Button)
                        If Not mpLogButton Is Nothing Then
                            mpLogButton.Text = "Log Out"
                        End If
                    End If
    
                    ClearValues()
                    RefreshList()
                    bindData()
                    bindData1()
                    findAndColorRowInGridView()
                    disabledText()
                    ChangeCommandStatus(1)
                    If Session("pageWise").ToString <> "" Then
                        PagewiseCheckBox.Checked = Session("pageWise")
                        GridView1.AllowPaging = True
                        GridView1.PageIndex = Convert.ToInt32(Session("pagingInfo"))
                    End If
    
    
                    Session("keyValue") = "0"
                    MessageLabel.CssClass = "SuccessMessage"
                    MessageLabel.Text = "New Entry"
    
                End If
            End If
    
        End Sub
    
        Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    
            If DropDownList1.Text = "" Then
                clearValues()
                Session("keyValue") = ""
                ChangeCommandStatus(1)
            Else
                Session("keyValue") = DropDownList1.Text
                displayData(Session("keyValue"))
                ChangeCommandStatus(2)
            End If
            findAndColorRowInGridView()
    
        End Sub
    
        Protected Sub PageList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PageList.SelectedIndexChanged
    
            GridView1.PageIndex = Convert.ToInt32(PageList.SelectedValue)
            'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
            bindData()
            findAndColorRowInGridView()
    
        End Sub
    
        Protected Sub PagewiseCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PagewiseCheckBox.CheckedChanged
    
            If PagewiseCheckBox.Checked = True Then
                GridView1.AllowPaging = True
            Else
                GridView1.AllowPaging = False
            End If
            'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
            bindData()
            findAndColorRowInGridView()
    
        End Sub
    
        Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
    
            'Clear our all of the items in the Dropdownlist
            PageList.Items.Clear()
    
            'Add a ListItem for each page
            For i As Integer = 0 To GridView1.PageCount - 1
                Dim pageListItem As New ListItem(String.Concat("Page ", i + 1), i.ToString())
                PageList.Items.Add(pageListItem)
    
                'select the current item, if needed
                If i = GridView1.PageIndex Then
                    pageListItem.Selected = True
                End If
            Next
    
        End Sub
    
        Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
    
            GridView1.PageIndex = Int32.Parse(e.NewPageIndex)
            bindData()
            'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
            findAndColorRowInGridView()
    
        End Sub
    
        Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
    
            If e.CommandName = "" Then
                Dim currentRowIndex As Integer = Int32.Parse(e.CommandArgument.ToString())
                Dim keyValue As String = GridView1.DataKeys(currentRowIndex).Value
                Session("keyValue") = keyValue
                DropDownList1.Text = keyValue
                MessageLabel.Text = ""
                displayData(keyValue)
    
            End If
    
        End Sub
    
        Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
    
            If e.Row.RowType = DataControlRowType.DataRow Then
                e.Row.Attributes.Add("onmouseover", "this.className='highlight'")
                e.Row.Attributes.Add("onmouseout", "this.className='normal'")
            End If
    
        End Sub
    
        Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    
            If e.Row.RowType = DataControlRowType.DataRow Then
                If GridView1.DataKeys(e.Row.RowIndex).Value.ToString <> "" Then
                    strSQL = "SELECT em_personqualificationdetail FROM employees WHERE em_employeeid = '" + GridView1.DataKeys(e.Row.RowIndex).Value.ToString + "'"
                    Dim DT As New DataTable
                    Try
                        Dim DA As New OleDbDataAdapter(strSQL, conn)
                        DA.Fill(DT)
                    Catch ex As Exception
                        MessageLabel.CssClass = "ErrorMessage"
                        MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                        Session("message1") = MessageLabel.Text
                        MesgBox()
                    End Try
                    If DT.Rows.Count = 1 Then
                        If DT.Rows(0).Item(0).ToString = "Y" Then
                            e.Row.Cells(0).BackColor = Drawing.Color.LightPink
                            e.Row.Cells(1).BackColor = Drawing.Color.LightPink
                            e.Row.Cells(2).BackColor = Drawing.Color.LightPink
                            e.Row.Cells(3).BackColor = Drawing.Color.LightPink
                        End If
                    End If
                End If
            End If
    
        End Sub
    
        Protected Sub QualificationGridView_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles QualificationGridView.RowCreated
    
            If e.Row.RowType = DataControlRowType.DataRow Then
                e.Row.Attributes.Add("onmouseover", "this.className='highlight'")
                e.Row.Attributes.Add("onmouseout", "this.className='normal'")
            End If
    
        End Sub
    
        Protected Sub QualificationGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles QualificationGridView.RowDataBound
    
            For Each gvr As GridViewRow In QualificationGridView.Rows
                If gvr.RowType = DataControlRowType.DataRow Then
                    Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(2).FindControl("QualificationDropDownList"), DropDownList)
    
                    'District List banaya
                    strSQL = "SELECT qm_qualificationid, qm_qualificationname FROM qualificationmaster ORDER BY qm_qualificationid ASC"
                    oleDbCommand.CommandType = CommandType.Text
                    oleDbCommand.CommandText = strSQL
                    oleDbCommand.Connection = conn
                    qualificationDropDownList.Items.Clear()
                    qualificationDropDownList.Items.Add(New ListItem("-Select-", ""))
                    qualificationDropDownList.Items.Add(New ListItem("-Other-", "0"))
                    Try
                        conn.Open()
                        qualificationDropDownList.DataSource = oleDbCommand.ExecuteReader()
                        qualificationDropDownList.DataTextField = "qm_qualificationname"
                        qualificationDropDownList.DataValueField = "qm_qualificationid"
                        qualificationDropDownList.DataBind()
                        conn.Close()
                    Catch ex As Exception
                        MessageLabel.CssClass = "ErrorMessage"
                        MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                        Session("message1") = MessageLabel.Text
                        MesgBox()
                    End Try
                End If
            Next
    
        End Sub
    
        Protected Sub QualificationGridView_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles QualificationGridView.RowDeleting
    
            ' Command Argument Property में मौजूद rowindex का वैल्यू निकालें.
            QualificationGridView.EditIndex = e.RowIndex
    
            ' Rows collection में उस row को निकालें जिसमे button मौजूद है.
            Dim gvr As GridViewRow = QualificationGridView.Rows(e.RowIndex)
    
            Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
            Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
            Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
            'Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
            'Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
            'Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
            'Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
            'Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
    
            strSQL = "DELETE FROM employeequalification WHERE eq_employeeid = '" + Session("keyValue").ToString + "' AND eq_qualificationid = '" + qualificationDropDownList.Text + "' AND eq_otherqualification = '" + otherqualificationTextBox.Text + "'"
            Try
                conn.Open()
                oleDbCommand = New OleDbCommand(strSQL, conn)
                oleDbCommand.ExecuteNonQuery()
                conn.Close()
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
    
            strSQL = "SELECT eq_employeeid FROM employeequalification WHERE eq_employeeid = '" + Session("keyValue").ToString + "'"
            Dim DT As New DataTable
            Try
                Dim DA As New OleDbDataAdapter(strSQL, conn)
                DA.Fill(DT)
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
    
            '
            If DT.Rows.Count = 0 Then
                'employees टेबल में em_personqualificationdetail फील्ड का वैल्यू  'N' करना हैं.
                strSQL = "UPDATE employees SET em_personqualificationdetail = 'N' WHERE em_employeeid = '" + Session("keyValue").ToString + "'"
                Try
                    conn.Open()
                    oleDbCommand = New OleDbCommand(strSQL, conn)
                    oleDbCommand.ExecuteNonQuery()
                    conn.Close()
                Catch ex As Exception
                    MessageLabel.CssClass = "ErrorMessage"
                    MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                    Session("message1") = MessageLabel.Text
                    MesgBox()
                End Try
            End If
            displayData(Session("keyValue").ToString)
    
        End Sub
    
        Protected Sub QualificationGridView_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles QualificationGridView.RowEditing
    
            ' rowindex का वैल्यू निकालें.
            QualificationGridView.EditIndex = e.NewEditIndex
    
            ' Rows collection में उस row को निकालें जिसमे button मौजूद है.
            Dim gvr As GridViewRow = QualificationGridView.Rows(e.NewEditIndex)
    
            ' सारे textbox और dropdownlist को enable कर दें ताकि अपडेट कर सकें.
            Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
            Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
            Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
            Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
            Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
            Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
            Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
            Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
            If selectCheckBox.Checked Then
                qualificationDropDownList.Enabled = True
                otherqualificationTextBox.Enabled = False
                streamsubjectTextBox.Enabled = True
                universityboardTextBox.Enabled = True
                schoolcollegeTextBox.Enabled = True
                passingyearTextBox.Enabled = True
                percentageTextBox.Enabled = True
            End If
    
        End Sub
    
        Public Sub SelectCheckBox_CheckedChanged()
    
            'Is button ka istemaal cancel command ko enable/disable karne ke vaste 
            Dim buttonValue As Integer = 0
    
            For Each gvr As GridViewRow In QualificationGridView.Rows
                If gvr.RowType = DataControlRowType.DataRow Then
                    Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                    Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
                    Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
                    Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
                    Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
                    Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
                    Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
                    Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
                    If selectCheckBox.Checked Then
                        qualificationDropDownList.Enabled = True
                        otherqualificationTextBox.Enabled = False
                        streamsubjectTextBox.Enabled = True
                        universityboardTextBox.Enabled = True
                        schoolcollegeTextBox.Enabled = True
                        passingyearTextBox.Enabled = True
                        percentageTextBox.Enabled = True
                        buttonValue = buttonValue + 1
                    Else
                        If buttonValue = gvr.RowIndex Then
                            selectCheckBox.Enabled = True
                        Else
                            selectCheckBox.Enabled = False
                        End If
                        qualificationDropDownList.Enabled = False
                        qualificationDropDownList.SelectedValue = ""
                        otherqualificationTextBox.Enabled = False
                        streamsubjectTextBox.Enabled = False
                        universityboardTextBox.Enabled = False
                        schoolcollegeTextBox.Enabled = False
                        passingyearTextBox.Enabled = False
                        percentageTextBox.Enabled = False
                    End If
                End If
            Next
    
            If buttonValue = 0 Then
                CancelButton.Enabled = False
            Else
                CancelButton.Enabled = True
            End If
    
        End Sub
    
        Public Sub QualificationDropDownList_SelectedIndexChanged()
    
            'Is button ka istemaal save command ko enable/disable karne ke liye
            Dim buttonValue As Integer = 0
            Dim varQualification As String
    
            For Each gvr As GridViewRow In QualificationGridView.Rows
                If gvr.RowType = DataControlRowType.DataRow Then
                    Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                    Dim qualificationDropDownList As DropDownList = DirectCast(gvr.FindControl("QualificationDropDownList"), DropDownList)
                    Dim otherqualificationTextBox As TextBox = DirectCast(gvr.FindControl("OtherQualificationTextBox"), TextBox)
    
                    'Enable/Disable otherqualificationtextbox
                    If selectCheckBox.Checked Then
                        If qualificationDropDownList.SelectedValue = "0" Then
                            otherqualificationTextBox.Enabled = True
                            otherqualificationTextBox.Focus()
                        Else
                            'यहाँ पर चेक करना है कि GRIDVIEW में क्वालिफिकेशन रिपीट तो नहीं हो रहा है.
                            varQualification = qualificationDropDownList.Text
    
                            'अगर क्वालिफिकेशन मेट्रिक से कम है तो gridview के उस row में सारे textbox को disable करना है.
                            Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
                            Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
                            Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
                            Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
                            Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
                            If CInt(Mid(qualificationDropDownList.Text, 10, 1)) <= 2 Then
                                streamsubjectTextBox.Enabled = False
                                universityboardTextBox.Enabled = False
                                schoolcollegeTextBox.Enabled = False
                                passingyearTextBox.Enabled = False
                                percentageTextBox.Enabled = False
                            Else
                                streamsubjectTextBox.Enabled = True
                                universityboardTextBox.Enabled = True
                                schoolcollegeTextBox.Enabled = True
                                passingyearTextBox.Enabled = True
                                percentageTextBox.Enabled = True
                            End If
                            otherqualificationTextBox.Text = ""
                            otherqualificationTextBox.Enabled = False
                        End If
                    Else
                        If qualificationDropDownList.Text = "" Then
                            otherqualificationTextBox.Text = ""
                            otherqualificationTextBox.Enabled = False
                        End If
                    End If
    
                    'Enable/Disable save command button
                    If qualificationDropDownList.SelectedValue <> "" Then
                        buttonValue = buttonValue + 1
                    End If
    
                End If
            Next
    
            If buttonValue = 0 Then
                SaveButton.Enabled = False
            Else
                SaveButton.Enabled = True
            End If
    
        End Sub
    
        Protected Sub SaveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveButton.Click
    
            Dim entryDate, empName, empNo As String
    
            entryDate = "'" + Now().ToShortDateString + "'"
            MessageLabel.Text = ""
            Session("message1") = ""
            Session("pageWise") = PagewiseCheckBox.Checked
            Session("pagingInfo") = PageList.Text
    
            'कर्मचारी का नाम को स्टोर करना है.
            strSQL = "SELECT em_empname FROM employees WHERE em_employeeid = '" + Session("keyValue").ToString + "'"
            Dim DT1 As New DataTable
            Try
                Dim DA As New OleDbDataAdapter(strSQL, conn)
                DA.Fill(DT1)
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
            If DT1.Rows.Count = 1 Then
                empName = DT1.Rows(0).Item(0).ToString
            Else
                empName = ""
            End If
    
            'employees टेबल में em_personqualificationdetail फील्ड का वैल्यू  'Y' करना हैं.
            strSQL = "UPDATE employees SET em_personqualificationdetail = 'Y' WHERE em_employeeid = '" + Session("keyValue").ToString + "'"
            Try
                conn.Open()
                oleDbCommand = New OleDbCommand(strSQL, conn)
                oleDbCommand.ExecuteNonQuery()
                conn.Close()
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
    
            'saving education details
            For Each gvr As GridViewRow In QualificationGridView.Rows
                If gvr.RowType = DataControlRowType.DataRow Then
                    Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                    Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
                    Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
                    Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
                    Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
                    Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
                    Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
                    Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
    
                    'Enable/Disable othertextbox
                    If selectCheckBox.Checked Then
                        strSQL = "INSERT into employeequalification (eq_employeeid, eq_qualificationid, eq_otherqualification, eq_streamsubject, eq_universityboard, eq_schoolcollege, eq_passingyear, eq_percentdivision, eq_createdby, eq_createdate) VALUES ('" + Session("keyValue").ToString + "', '" + qualificationDropDownList.Text + "', '" + otherqualificationTextBox.Text.ToUpper + "', '" + streamsubjectTextBox.Text.ToUpper + "', '" + universityboardTextBox.Text.ToUpper + "', '" + schoolcollegeTextBox.Text.ToUpper + "', '" + passingyearTextBox.Text + "', '" + percentageTextBox.Text + "', '" + Session("userID").ToString + "', " + entryDate + ")"
                        Try
                            conn.Open()
                            oleDbCommand = New OleDbCommand(strSQL, conn)
                            oleDbCommand.ExecuteNonQuery()
                            conn.Close()
                        Catch ex As Exception
                            MessageLabel.CssClass = "ErrorMessage"
                            MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                            Session("message1") = MessageLabel.Text
                            MesgBox()
                        End Try
                    End If
    
                End If
            Next
    
            empNo = Session("keyValue").ToString
            Session("keyValue") = "0" 'Is session variable ko yahin par saaf karna matlab 0(zero) taki update ke check na kare.
            RefreshList()
            ChangeCommandStatus(1)
            ClearValues()
            disabledText()
            bindData()
    
            If Len(MessageLabel.Text) = 0 Then
                MessageLabel.CssClass = "SuccessMessage"
                MessageLabel.Text = "व्यक्ति " + empNo + " [" + empName + "] का एजुकेशनल डिटेल्स सफलतापूर्वक सेव कर लिया गया है."
                Session("message1") = MessageLabel.Text
                MesgBox()
            Else
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = "माफ़ कीजिये! व्यक्ति " + empNo + " [" + empName + "] का एजुकेशनल डिटेल्स सेव नहीं हो पाया है."
                Session("message1") = MessageLabel.Text
                MesgBox()
            End If
    
        End Sub
    
        Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
    
            Dim entryDate, empNo, empName As String
    
            entryDate = "'" + Now().ToShortDateString + "'"
            MessageLabel.Text = ""
            Session("message1") = ""
            Session("pageWise") = PagewiseCheckBox.Checked
            Session("pagingInfo") = PageList.Text
    
            'Employee name ko store karna hai.
            strSQL = "SELECT em_empname, em_personqualificationdetail FROM employees WHERE em_employeeid = '" + Session("keyValue").ToString + "'"
            Dim DT1 As New DataTable
            Try
                Dim DA As New OleDbDataAdapter(strSQL, conn)
                DA.Fill(DT1)
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
            If DT1.Rows.Count = 1 Then
                empName = DT1.Rows(0).Item(0).ToString
            Else
                empName = ""
            End If
    
            'employee ka education equalification check karo, agar pahle se hai to update karo nahi to insert karo
            strSQL = "SELECT eq_employeeid, eq_qualificationid FROM employeequalification WHERE eq_employeeid = '" + Session("keyValue").ToString + "'"
            Dim DT As New DataTable
            Try
                Dim DA As New OleDbDataAdapter(strSQL, conn)
                DA.Fill(DT)
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
    
            'Updating education details record.
            For Each gvr As GridViewRow In QualificationGridView.Rows
                If gvr.RowType = DataControlRowType.DataRow Then
                    Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                    Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
                    Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
                    Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
                    Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
                    Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
                    Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
                    Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
    
    
                    'Enable/Disable othertextbox
                    If selectCheckBox.Checked Then
                        If DT.Rows.Count > 0 Then
                            Dim counter As Integer = 0
                            Do While counter < DT.Rows.Count
                                If DT.Rows(counter).Item(1).ToString = qualificationDropDownList.Text Then
                                    strSQL = "UPDATE employeequalification SET eq_qualificationid = '" + qualificationDropDownList.Text + "', eq_otherqualification = '" + otherqualificationTextBox.Text.ToUpper + "', eq_streamsubject = '" + streamsubjectTextBox.Text.ToUpper + "', eq_universityboard = '" + universityboardTextBox.Text.ToUpper + "', eq_schoolcollege = '" + schoolcollegeTextBox.Text.ToUpper + "', eq_passingyear = '" + passingyearTextBox.Text + "', eq_percentdivision = '" + percentageTextBox.Text + "', eq_updatedby = '" + Session("userID").ToString + "', eq_updatedate = " + entryDate + " WHERE eq_employeeid = '" + Session("keyValue").ToString + "' AND eq_qualificationid = '" + qualificationDropDownList.Text + "'"
                                    Try
                                        conn.Open()
                                        oleDbCommand = New OleDbCommand(strSQL, conn)
                                        oleDbCommand.ExecuteNonQuery()
                                        conn.Close()
                                    Catch ex As Exception
                                        MessageLabel.CssClass = "ErrorMessage"
                                        MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                                        Session("message1") = MessageLabel.Text
                                        MesgBox()
                                    End Try
                                    counter = DT.Rows.Count + 1
                                Else
                                    counter = counter + 1
                                End If
                            Loop
                            If counter = DT.Rows.Count Then
                                strSQL = "INSERT into employeequalification (eq_employeeid, eq_qualificationid, eq_otherqualification, eq_streamsubject, eq_universityboard, eq_schoolcollege, eq_passingyear, eq_percentdivision, eq_createdby, eq_createdate) VALUES ('" + Session("keyValue").ToString + "', '" + qualificationDropDownList.Text + "', '" + otherqualificationTextBox.Text.ToUpper + "', '" + streamsubjectTextBox.Text.ToUpper + "', '" + universityboardTextBox.Text.ToUpper + "', '" + schoolcollegeTextBox.Text.ToUpper + "', '" + passingyearTextBox.Text + "', '" + percentageTextBox.Text + "', '" + Session("userID").ToString + "', " + entryDate + ")"
                                Try
                                    conn.Open()
                                    oleDbCommand = New OleDbCommand(strSQL, conn)
                                    oleDbCommand.ExecuteNonQuery()
                                    conn.Close()
                                Catch ex As Exception
                                    MessageLabel.CssClass = "ErrorMessage"
                                    MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                                    Session("message1") = MessageLabel.Text
                                    MesgBox()
                                End Try
                            End If
                        End If
                    End If
    
                End If
            Next
    
            empNo = Session("keyValue").ToString
            Session("keyValue") = "0" 'Is session variable ko yahin par saaf karna matlab 0(zero) taki update ke check na kare.
            RefreshList()
            ChangeCommandStatus(1)
            ClearValues()
            disabledText()
            bindData()
    
    
            If Len(MessageLabel.Text) = 0 Then
                MessageLabel.CssClass = "SuccessMessage"
                MessageLabel.Text = "व्यक्ति " + empNo + " [" + empName + "] का एजुकेशनल डिटेल्स सफलतापूर्वक अपडेट कर लिया गया है."
                Session("message1") = MessageLabel.Text
                MesgBox()
            Else
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = "माफ़ कीजिये! व्यक्ति " + empNo + " [" + empName + "] का एजुकेशनल डिटेल्स अपडेट नहीं हो पाया है."
                Session("message1") = MessageLabel.Text
                MesgBox()
            End If
    
        End Sub
    
        Protected Sub CancelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CancelButton.Click
    
            RefreshList()
            ChangeCommandStatus(1)
            ClearValues()
            disabledText()
            Session("keyValue") = "0"
            DropDownList1.Text = ""
            bindData()
            MessageLabel.CssClass = "SuccessMessage"
            MessageLabel.Text = "New Entry"
    
        End Sub
    
        Protected Sub BackButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BackButton.Click
    
            ChangeCommandStatus(0)
            clearValues()
            Session("keyValue") = "0"
            Response.Redirect("Default.aspx")
    
        End Sub
    
        Sub displayData(ByVal keyValue As String)
    
            ClearValues()
            'extract name and flag for new or old data
            strSQL = "SELECT em_employeeid, em_empname, em_personqualificationdetail FROM employees WHERE em_employeeid = '" + keyValue + "'"
            Dim DT1 As New DataTable
            Try
                Dim DA As New OleDbDataAdapter(strSQL, conn)
                DA.Fill(DT1)
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
    
            If DT1.Rows.Count = 1 Then
                NameTextLabel.Text = DT1.Rows(0).Item(1).ToString
                If DT1.Rows(0).Item(2).ToString = "" Then
                    ChangeCommandStatus(1)  'Enable/disable command buttons
                Else
                    ChangeCommandStatus(2)  'Enable/disable command buttons
                End If
            End If
    
            strSQL = "SELECT eq_employeeid, eq_qualificationid, eq_otherqualification, eq_streamsubject, eq_universityboard, eq_schoolcollege, eq_passingyear, eq_percentdivision FROM employeequalification WHERE eq_employeeid = '" + keyValue + "'"
            Dim DT As New DataTable
            Try
                Dim DA As New OleDbDataAdapter(strSQL, conn)
                DA.Fill(DT)
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
    
            'Edit interface me data bharaa
            If DT.Rows.Count > 0 Then
                Dim counter As Integer = 0
                For Each gvr As GridViewRow In QualificationGridView.Rows
                    If gvr.RowType = DataControlRowType.DataRow Then
                        If counter < DT.Rows.Count Then
                            Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                            Dim editButton As Button = CType(gvr.Cells(2).FindControl("EditButton"), Button)
                            Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
                            Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
                            Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
                            Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
                            Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
                            Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
                            Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
                            Dim deleteButton As Button = CType(gvr.Cells(10).FindControl("DeleteButton"), Button)
                            qualificationDropDownList.Text = DT.Rows(counter).Item(1).ToString
                            otherqualificationTextBox.Text = DT.Rows(counter).Item(2).ToString
                            streamsubjectTextBox.Text = DT.Rows(counter).Item(3).ToString
                            universityboardTextBox.Text = DT.Rows(counter).Item(4).ToString
                            schoolcollegeTextBox.Text = DT.Rows(counter).Item(5).ToString
                            passingyearTextBox.Text = DT.Rows(counter).Item(6).ToString
                            percentageTextBox.Text = DT.Rows(counter).Item(7).ToString
                            selectCheckBox.Checked = True
                            selectCheckBox.Enabled = False
                            editButton.Enabled = True
                            deleteButton.Enabled = True
                            counter = counter + 1
                        End If
    
                    End If
                    Dim select1CheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                    If counter = gvr.RowIndex Then
                        select1CheckBox.Enabled = True
                    Else
                        select1CheckBox.Enabled = False
                    End If
                Next
    
            Else
                For Each gvr As GridViewRow In QualificationGridView.Rows
                    Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                    If gvr.RowIndex = 0 Then
                        selectCheckBox.Enabled = True
                    Else
                        selectCheckBox.Enabled = False
                    End If
                Next
            End If
    
            'selected row ka color change karo.
            'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
            findAndColorRowInGridView()
    
        End Sub
    
        Private Sub bindData()
    
            strSQL = "SELECT em_employeeid, em_empname, em_birthdate FROM employees WHERE MID(em_employeeid,3,2) <>'00' ORDER BY em_employeeid ASC"
            Dim DT As New DataTable
            Try
                Dim DA As New OleDbDataAdapter(strSQL, conn)
                DA.Fill(DT)
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
            If DT.Rows.Count > 0 Then
                If DT.Rows.Count > GridView1.PageSize Then
                    PagingLabel.Enabled = True
                    PageList.Enabled = True
                    PagewiseCheckBox.Enabled = True
                Else
                    PagingLabel.Enabled = False
                    PageList.Enabled = False
                    PagewiseCheckBox.Enabled = False
                End If
                GridView1.DataSource = DT
                GridView1.DataBind()
            Else
                GridView1.DataSource = Nothing
                GridView1.DataBind()
            End If
    
        End Sub
    
        Private Sub bindData1()
    
            strSQL = "SELECT qm_qualificationid, qm_qualificationname FROM qualificationmaster"
            Dim DT As New DataTable
            Try
                Dim DA As New OleDbDataAdapter(strSQL, conn)
                DA.Fill(DT)
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
            If DT.Rows.Count > 0 Then
                QualificationGridView.DataSource = DT
                QualificationGridView.DataBind()
            Else
                QualificationGridView.DataSource = Nothing
                QualificationGridView.DataBind()
            End If
    
        End Sub
    
        Sub RefreshList()
    
            'List ko refresh kiya
            strSQL = "SELECT em_employeeid, em_empname FROM employees WHERE MID(em_employeeid,3,2) <>'00' ORDER BY em_empname ASC"
            oleDbCommand.CommandType = CommandType.Text
            oleDbCommand.CommandText = strSQL
            oleDbCommand.Connection = conn
            DropDownList1.Items.Clear()
            DropDownList1.Items.Add(New ListItem("-चुनें-", ""))
            Try
                conn.Open()
                DropDownList1.DataSource = oleDbCommand.ExecuteReader()
                DropDownList1.DataTextField = "em_empname"
                DropDownList1.DataValueField = "em_employeeid"
                DropDownList1.DataBind()
                conn.Close()
            Catch ex As Exception
                MessageLabel.CssClass = "ErrorMessage"
                MessageLabel.Text = webService.DisplayExceptionDetails(ex)
                Session("message1") = MessageLabel.Text
                MesgBox()
            End Try
    
        End Sub
    
        Private Sub ClearValues()
    
            NameTextLabel.Text = ""
            For Each gvr As GridViewRow In QualificationGridView.Rows
                If gvr.RowType = DataControlRowType.DataRow Then
                    Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                    Dim editButton As Button = CType(gvr.Cells(2).FindControl("EditButton"), Button)
                    Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
                    Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
                    Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
                    Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
                    Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
                    Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
                    Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
                    Dim deleteButton As Button = CType(gvr.Cells(10).FindControl("DeleteButton"), Button)
                    If selectCheckBox.Checked Then
                        selectCheckBox.Checked = False
                    End If
                    editButton.Enabled = False
                    qualificationDropDownList.Enabled = False
                    qualificationDropDownList.SelectedValue = ""
                    otherqualificationTextBox.Enabled = False
                    otherqualificationTextBox.Text = ""
                    streamsubjectTextBox.Enabled = False
                    streamsubjectTextBox.Text = ""
                    universityboardTextBox.Enabled = False
                    universityboardTextBox.Text = ""
                    schoolcollegeTextBox.Enabled = False
                    schoolcollegeTextBox.Text = ""
                    passingyearTextBox.Enabled = False
                    passingyearTextBox.Text = ""
                    percentageTextBox.Enabled = False
                    percentageTextBox.Text = ""
                    deleteButton.Enabled = False
                End If
            Next
    
        End Sub
    
        Private Sub disabledText()
    
            NameTextLabel.Enabled = False
            For Each gvr As GridViewRow In QualificationGridView.Rows
                If gvr.RowType = DataControlRowType.DataRow Then
                    Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                    Dim editButton As Button = CType(gvr.Cells(2).FindControl("EditButton"), Button)
                    Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
                    Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
                    Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
                    Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
                    Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
                    Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
                    Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
                    Dim deleteButton As Button = CType(gvr.Cells(10).FindControl("DeleteButton"), Button)
                    If selectCheckBox.Checked Then
                        selectCheckBox.Checked = False
                    End If
                    selectCheckBox.Enabled = False
                    editButton.Enabled = False
                    qualificationDropDownList.Enabled = False
                    qualificationDropDownList.SelectedValue = ""
                    otherqualificationTextBox.Enabled = False
                    otherqualificationTextBox.Text = ""
                    streamsubjectTextBox.Enabled = False
                    streamsubjectTextBox.Text = ""
                    universityboardTextBox.Enabled = False
                    universityboardTextBox.Text = ""
                    schoolcollegeTextBox.Enabled = False
                    schoolcollegeTextBox.Text = ""
                    passingyearTextBox.Enabled = False
                    passingyearTextBox.Text = ""
                    percentageTextBox.Enabled = False
                    percentageTextBox.Text = ""
                    deleteButton.Enabled = False
                End If
            Next
    
        End Sub
    
        Private Sub enabledText()
    
            NameTextLabel.Enabled = True
            For Each gvr As GridViewRow In QualificationGridView.Rows
                If gvr.RowType = DataControlRowType.DataRow Then
                    Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
                    If selectCheckBox.Checked Then
                        selectCheckBox.Checked = False
                    End If
                    selectCheckBox.Enabled = True
                End If
            Next
    
        End Sub
    
        Private Sub ChangeCommandStatus(ByVal saveStatus As Integer)
    
            If saveStatus = 1 Then
                SaveButton.Enabled = True
                UpdateButton.Enabled = False
                CancelButton.Enabled = True
            ElseIf saveStatus = 2 Then
                SaveButton.Enabled = False
                UpdateButton.Enabled = True
                CancelButton.Enabled = True
            Else
                SaveButton.Enabled = False
                UpdateButton.Enabled = False
                CancelButton.Enabled = False
            End If
    
        End Sub
    
        Sub findAndColorRowInGridView()
    
            'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
            For Each gvr As GridViewRow In GridView1.Rows
                Dim keyValue As LinkButton = DirectCast(gvr.Cells(1).Controls(0), LinkButton)
                If keyValue.Text = Session("keyValue") Then
                    GridView1.Rows(gvr.RowIndex).BackColor = Drawing.Color.Yellow
                Else
                    GridView1.Rows(gvr.RowIndex).BackColor = Drawing.Color.Transparent
                End If
            Next
    
        End Sub
    
        Private Sub MesgBox()
    
            Session("appName") = "PersonQualificationDetail.aspx"
            Response.Redirect("Message.aspx")
    
        End Sub
    
    End Class
    



    Tuesday, October 18, 2016 2:02 PM
  • User-691209617 posted

    You have code in you Page_Load event so add this 

    if (!Page.IsPostBack)
    { //do something }

    This error is thrown when you click on your command and the Page_load is being ran again, in a normal life cycle will be Page_Load -> Click on Command -> Page_Load (again) -> Process ItemCommand Event.

    Also, add this

    <%@ Page EnableEventValidation="false" %>

    Hope it helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 18, 2016 3:02 PM
  • User390265149 posted

    My problem is solved with this option

    <%@ Page EnableEventValidation="false" %>

    I found a security note in using this option and suggested for use of  'RegisterForEventValidation'.

    So how can I use this in place of 'EnableEventValidation="false"'

    Wednesday, October 19, 2016 9:22 AM
  • User-691209617 posted

    Hi Vikas,

    The problem is that ASP.NET does not get to know about this extra or removed listitem. You got an number of options (listed below):

    • Disable eventvalidation (bad idea, because you lose a little of security that come with very little cost).
    • Use ASP.NET Ajax UpdatePanel. (Put the listbox in the Updatepanel and trigger a update, if you add or remove listbox. This way viewstate and related fields get updates and eventvalidation will pass.)
    • Forget client-side and use the classic postback and add or remove the listitems server-side

    Please use update panel in your case and it will solve your problem. if you want I can send you some working example of update panel.

    I hope this helps.

    Wednesday, October 19, 2016 12:48 PM
  • User390265149 posted

    Thankyou sir. I like this answer.

    Wednesday, October 19, 2016 1:51 PM
  • User-691209617 posted

    If that help then mark it as answer so it is beneficial for others too.

    Wednesday, October 19, 2016 2:09 PM