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 6747271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:25:19+00:00 2026-05-26T12:25:19+00:00

I can’t get my textbox to update the database. The changes look like they

  • 0

I can’t get my textbox to update the database. The changes look like they are saved (they are saved on the page) and the modal pop up goes away, but the text that I tried to change in the database stays the same.

Protected Sub SubmitEdit_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim myControl As Control = FindControl("txtData")
    If (Not myControl Is Nothing) Then
        Dim UpdateSql As String = "UPDATE Picklist SET (Data) = @Data WHERE PicklistID = @PicklistID"
        Using cn As New SqlConnection
        (System.Configuration.ConfigurationManager.ConnectionStrings
        ("LocalSqlServer").ConnectionString)
            Using sqlcmd As New SqlCommand(UpdateSql, cn)
                sqlcmd.Parameters.Add(New SqlParameter("@Data", myControl))
                cn.Open()
                sqlcmd.ExecuteNonQuery()
            End Using
        End Using
    Else
    End If
End Sub


 <asp:TabPanel ID="tab2"  runat="server" HeaderText="Descriptions">
<HeaderTemplate>Descriptions</HeaderTemplate>
    <ContentTemplate>
        <ul class="info">
        <asp:ListView ID="lvDescriptions" runat="server" 
          DataSourceID="dsAdminMarketingDescriptions" DataKeyNames="MarketingID">

        <ItemTemplate>
            <li class="item">
                <asp:LinkButton ID="ViewDescriptionButton" runat="server">
                <%# Eval("Title")%>
                </asp:LinkButton>

               <asp:ImageButton ID="DeleteDescriptionButton" runat="server"  
                Style="float:right;" AlternateText="" 
                ImageUrl="../../images/delete.png" CommandName="Delete" 
                OnClientClick="return confirm('Are you sure you want to delete this 
                description?')" />

                <asp:Panel ID="ViewDescriptionPanel" runat="server"
                  CssClass="DescModalPopup">                                   
                <div class="PopupHeader">View Description -- <%#Eval("Title") %>
                <asp:ImageButton ID="CancelDescriptionButton" runat="server" 
                  ImageUrl="../../images/cancel.png" AlternateText="" 
                  Style="float:right;"/>
                 <asp:ImageButton ID="EditDescriptionButton" runat="server" 
                   ImageUrl="../../images/edit.png" AlternateText="" 
                   Style="float:right;" CommandName="Edit" AutoPostBack="false" />
                </div>

                    <asp:Label ID="Description" runat="server" style="padding:2px;">
                    <%# Eval("Data")%>
                    </asp:Label>
                </asp:Panel> 

                <asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server" 
                  BackgroundCssClass="modalBackground" DropShadow="false" 
                  DynamicServicePath="" Enabled="true" 
                  PopupControlID="ViewDescriptionPanel" 
                  TargetControlID="ViewDescriptionButton" 
                  CancelControlID="CancelDescriptionButton"></asp:ModalPopupExtender> 


                <asp:Panel ID="EditDescriptionPanel" runat="server" 
                  CssClass="DescModalPopup">

                <div class="PopupHeader">Edit Description -- <%# Eval("Title")%>
                <asp:ImageButton ID="Cancel" runat="server" 
                  ImageUrl="../../images/cancel.png" AlternateText="" 
                  Style="float:right;"/>
                </div>

                    <asp:TextBox ID="txtData" runat="server" TextMode="MultiLine" 
                     Text='<%# Eval("Data")%>'>
                    </asp:TextBox><br />
                <asp:Button ID="SubmitEdit" runat="server" Text="Submit" />
                <asp:Button ID="CancelEdit" runat="server" Text="Cancel" />
                </asp:Panel>

                <asp:ModalPopupExtender ID="EditDescriptionModal" runat="server" 
                BackgroundCssClass="modalBackground" DropShadow="false" 
                DynamicServicePath="" Enabled="true" 
                PopupControlID="EditDescriptionPanel" 
                TargetControlID="EditDescriptionButton">
                </asp:ModalPopupExtender>            
            </li>
        </ItemTemplate>

UPDATE: I tried using a try catch to get an error message, but it didn’t work.

Protected Sub SubmitEdit_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim myControl As Control = FindControl("txtData")
    If (Not myControl Is Nothing) Then
        Try
            Dim UpdateSql As String = "UPDATE Picklist 
                                       SET (Data) = @Data 
                                       WHERE Title = @Title"
            Using cn As New SqlConnection
             (System.Configuration.ConfigurationManager.ConnectionStrings
             ("LocalSqlServer").ConnectionString)
                Using sqlcmd As New SqlCommand(UpdateSql, cn)
                    sqlcmd.Parameters.Add(New SqlParameter("@Data", 
                     DirectCast(myControl, TextBox).Text))
                    cn.Open()
                    sqlcmd.ExecuteNonQuery()
                End Using
                cn.Close()
            End Using
        Catch ex As Exception
            Response.Write(ex.Message())
        End Try
    Else
    End If
    Response.Redirect(Request.RawUrl)
End Sub

UPDATE: Figured it out. Here is the code behind, all other code stayed the same

Protected Sub SubmitEdit_Click(ByVal sender As Object, ByVal e As EventArgs)
    For Each item As ListViewDataItem In lvDescriptions.Items
        Dim txtData As TextBox = DirectCast(item.FindControl("txtData"), TextBox)
        Dim ltlTitle As Literal = DirectCast(item.FindControl("ltlTitle"), Literal)
        Dim UpdateSql As String = "UPDATE Picklist 
                                   SET Data = @Data 
                                   WHERE Title = @Title"
        Using cn As New SqlConnection
        (System.Configuration.ConfigurationManager.ConnectionStrings
        ("LocalSqlServer").ConnectionString)
            Using sqlcmd As New SqlCommand(UpdateSql, cn)
                sqlcmd.Parameters.Add(New SqlParameter("@Data", txtData.Text))
                sqlcmd.Parameters.Add(New SqlParameter("@Title", ltlTitle.Text))

                cn.Open()
                sqlcmd.ExecuteNonQuery()

            End Using
            cn.Close()
        End Using
    Next
    Response.Redirect(Request.RawUrl)
End Sub
  • 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-26T12:25:20+00:00Added an answer on May 26, 2026 at 12:25 pm

    You need to change the line:

    sqlcmd.Parameters.Add(New SqlParameter("@Data", myControl))
    

    to

    sqlcmd.Parameters.Add(New SqlParameter("@Data", myControl.Text))
    

    Update:

    Since the textbox is in a listview itemtemplate, you also need to change how it is discovered by looking at the currently selected list item. To do this, change the following line:

    Dim myControl As Control = FindControl("txtData")
    

    to:

    Dim myControl As TextBox = DirectCast(lvDescriptions.Items(lvDescriptions.SelectedIndex).FindControl("txtData"), TextBox)
    

    I have also updated the sqlParameters assignment to remove the DirectCast since we are now declaring the control as a TextBox (but it still needs to be updated to use the Text property from the original code).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me how I can display a status message like 12 seconds
Can I get a 'when to use' for these and others? <% %> <%#
Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox
Can I store an array such as [1,2,3,4] or some JSON like {name:John Johnson,street:Oslo,
Can i get the source code for a WAMP stack installer somewhere? Any help
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can we use the asterisk character * for a search action in SQL database?
Can we close all known/unknown connections to database with the code? I'm using Access
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can someone help me? I am trying to do something like the following: #include

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.