#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Updating SQL on click / toggle


    Hi guys,
    This is my first post here so sorry if I do anything wrong.
    I am really struggling with an issue that I have and I would be really grateful of any help that I can get.

    I have a list of people that is taken from a database, and they all have a column called "InBuilding".
    The idea of this list is that people can click on it when they are in the building and their name will go bold and the background colour of the cell changes.

    I have currently set it so that the CSS is defined by the "InBuilding" value so that when the page loads, the correct people are in bold however the class is toggleable by using jQuery so when you click on the name it behaves in the way I described above.

    The main issue is that I cannot get this click to cause an update in the SQL database and I cannot figure it out. This causes all of the highlight information to be lost on refresh.

    Does anyone know of a good starting point?

    Here is what I have got so far:
    This is my aspx page
    Code:
      <asp:Repeater ID="InBuildingPenpontRepeater" runat="server" DataSourceID="PenpontInBuildingDataSource">
                                <HeaderTemplate><ul class="RMenuList InBuilding noSelect NonMobile"><li class="InBuildingTitle">Penpont</li></HeaderTemplate>
                                <ItemTemplate>
                                    <li class="<%#Eval("InBuilding")%> InBuildingtickable" id="InBuildingPenpontli" onclick="InBuildingToggle"><%#Eval("NameDisplay")%></li>
                                </ItemTemplate>
                                <FooterTemplate></ul></FooterTemplate>
                            </asp:Repeater>
                            <asp:SqlDataSource runat="server" ID="PenpontInBuildingDataSource" ConnectionString='<%$ ConnectionStrings:BMDbaseConnectionString %>' SelectCommand="SELECT * FROM CHRISHTESTInBuilding WHERE Active=1 AND 
    (Staff_ID=1 OR Staff_ID=2 OR Staff_ID=3 OR Staff_ID=4 OR Staff_ID=5 OR Staff_ID=6 OR Staff_ID=7 OR Staff_ID=8 OR Staff_ID=9 OR Staff_ID=10 OR Staff_ID=11 OR Staff_ID=12 OR Staff_ID=13 OR Staff_ID=14)
    ORDER BY NameDisplay" UpdateCommand="UPDATE CHRISHTESTInBuilding SET [InBuilding] = @InBuilding WHERE [Staff_ID] = @Staff_ID"></asp:SqlDataSource>
    And this is the codeBehind:

    Code:
    Protected Sub InBuildingToggle()
            Dim mySqlUpdate As String = "Update CHRISHTESTInBuilding SET [InBuilding] = 1 WHERE Staff_ID = @Staff_ID"
            Me.PenpontInBuildingDataSource.UpdateCommand = mySqlUpdate
            Me.PenpontInBuildingDataSource.Update()
    
    
        End Sub
    This is the CSS Class that I am using based on the "InBuilding" field:
    Code:
    .InBuilding .True {
        background-color: #CFCFCF;
        font-weight:bold;
    }
    This should be really simple, and maybe I am over thinking it, but I just can't get this to behave the way I want to.

    I really do appreciate any help that I can get because this is driving me slightly batty at the moment

    Thank you
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Updating SQL on click / toggle


    This works fine, except that I have to click button two times the first time to change the status. later itr works fine. Anyone knows how to fix that?

IMN logo majestic logo threadwatch logo seochat tools logo