Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 745429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:05:37+00:00 2026-05-14T09:05:37+00:00

This is really driving me crazy. I’ve got a button inside a gridview to

  • 0

This is really driving me crazy. I’ve got a button inside a gridview to remove that item from the gridview (its datasource is a list). I’ve got the list being saved to session anytime a change is being made to it, and on page_load check if that session variable is empty, if not, then set that list to bind to the gridview.

Code Behind:

Public accomplishmentTypeDao As New AccomplishmentTypeDao()
Public accomplishmentDao As New AccomplishmentDao()
Public userDao As New UserDao()
Public facultyDictionary As New Dictionary(Of Guid, String)
Public facultyList As New List(Of User)
Public associatedFaculty As New List(Of User)
Public facultyId As New Guid

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    'If Not Session("associatedFaculty") Is Nothing Then'
    '   Dim associatedFacultyArray As User() = DirectCast(Session("associatedFaculty"), User())'
    '   associatedFaculty = associatedFacultyArray.ToList()'
    'End If'

    Page.Title = "Add a New Faculty Accomplishment"

    ddlAccomplishmentType.DataSource = accomplishmentTypeDao.getEntireTable()
    ddlAccomplishmentType.DataTextField = "Name"
    ddlAccomplishmentType.DataValueField = "Id"
    ddlAccomplishmentType.DataBind()

    facultyList = userDao.getListOfUsersByUserGroupName("Faculty")

    For Each faculty As User In facultyList
        facultyDictionary.Add(faculty.Id, faculty.LastName & ", " & faculty.FirstName)
    Next

    If Not Page.IsPostBack Then
        ddlFacultyList.DataSource = facultyDictionary
        ddlFacultyList.DataTextField = "Value"
        ddlFacultyList.DataValueField = "Key"
        ddlFacultyList.DataBind()
    End If

    gvAssociatedUsers.DataSource = associatedFaculty
    gvAssociatedUsers.DataBind()

End Sub

Protected Sub deleteUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
    facultyId = New Guid(e.CommandArgument.ToString())
    associatedFaculty.Remove(associatedFaculty.Find(Function(user) user.Id = facultyId))
    Session("associatedFaculty") = associatedFaculty.ToArray()
    gvAssociatedUsers.DataBind()
    upAssociatedFaculty.Update()
End Sub

Protected Sub btnAddUser_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAddUser.Click
    facultyId = New Guid(ddlFacultyList.SelectedValue)
    associatedFaculty.Add(facultyList.Find(Function(user) user.Id = facultyId))
    Session.Add("associatedFaculty", associatedFaculty.ToArray())
    gvAssociatedUsers.DataBind()
    upAssociatedFaculty.Update()
End Sub

Protected Sub Delete(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)

End Sub

End Class

Markup:

<asp:UpdatePanel ID="upAssociatedFaculty" runat="server" 
    UpdateMode="Conditional">
    <ContentTemplate>
<p><b>Created By:</b> <asp:Label ID="lblCreatedBy" runat="server"></asp:Label></p>
<p><b>Accomplishment Type: </b><asp:DropDownList ID="ddlAccomplishmentType" runat="server"></asp:DropDownList></p>

        <p><b>Accomplishment Applies To: </b><asp:DropDownList ID="ddlFacultyList" runat="server"></asp:DropDownList>
            &nbsp;<asp:Button ID="btnAddUser" runat="server" Text="Add Faculty" OnClientClick="incrementCounter();" /></p>

        <p>
            <asp:GridView ID="gvAssociatedUsers" runat="server" AutoGenerateColumns="false" 
                GridLines="None" ShowHeader="false">
                <Columns>
                     <asp:BoundField DataField="Id" HeaderText="Id" Visible="False" />
                     <asp:TemplateField ShowHeader="False">
                         <ItemTemplate>
                             <span style="margin-left: 15px;">
                                <p><%#Eval("LastName")%>, <%#Eval("FirstName")%>
                                <asp:Button ID="btnUnassignUser" runat="server" CausesValidation="false" 
                                     CommandArgument='<%# Eval("Id") %>' CommandName="Delete" OnCommand="deleteUser" Text='Remove' /></p>
                             </span>
                         </ItemTemplate>
                     </asp:TemplateField>
                 </Columns>
                 <EmptyDataTemplate>
                     <em>There are currently no faculty associated with this accomplishment.</em>
                 </EmptyDataTemplate>
            </asp:GridView>
        </p>
    </ContentTemplate>
</asp:UpdatePanel>

Now here is the crazy part I am simply boggled by, if I uncomment the If Not Session... block of page_load, then deleteUser will never fire when btnUnassignUser is clicked. If I keep it commented out…it fires no problem, but then of course my list can never have more than one item since I am not loading the saved list from session into the gridview but just a fresh one. But the button click is being registered, because page_load is being stepped through again when I am viewing in debug mode, just deleteUser never fires.

Why is this happening?? And how can I fix it??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:05:38+00:00Added an answer on May 14, 2026 at 9:05 am

    You don’t want to keep rebinding the grid. You want the grid to have the datasource again, but not to be reset.

       gvAssociatedUsers.DataSource = associatedFaculty
       if (!Page.IsPostBack)
           gvAssociatedUsers.DataBind()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.