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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:39:01+00:00 2026-05-28T04:39:01+00:00

This is my datalist: <asp:DataList ID=DataList1 runat=server DataSourceID=SqlDataSource1 RepeatLayout=Flow> <ItemTemplate> <asp:Label ID=IdLabel runat=server Text='<%#

  • 0

This is my datalist:

    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" 
               RepeatLayout="Flow">
            <ItemTemplate>

                <asp:Label ID="IdLabel" runat="server" Text='<%# Eval("ID") %>'  Visible="False" />
                Titre:
                <asp:Label ID="TitreLabel" runat="server" Text='<%# Eval("Titre") %>' />
                <br />
                Description:
                <asp:Label ID="DescriptionLabel" runat="server" 
                    Text='<%# Eval("Description") %>' />
                <br />

                <asp:Image ID="Image1" runat="server" 
                 ImageUrl='<%# Eval("ID", "Handler.ashx?ID={0}") %>' Width="200" Height="200"/>

                <br />
                comments:
                <asp:Label ID="commentsLabel" runat="server" Text='<%# Eval("comments") %>' />
                <br />

                Ajouter commentaire 
                <asp:button ID="btnAjouter"  runat="server" OnCommand="Button_Command"
                 CommandName="add" Text="Ajouter" />
                <asp:TextBox ID="TextBoxComments" runat="server"></asp:TextBox>
                <br/>
                <br/>
            </ItemTemplate>
        </asp:DataList>

This my aspx.vb button event:

Sub Button_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
    Dim connectionString As String = WebConfigurationManager.ConnectionStrings("BecsEtMuseauxSQL").ConnectionString
    Dim con As SqlConnection = New SqlConnection(connectionString)

    con.Open()

    Dim cmd As New SqlCommand("updateComments", con)
    cmd.CommandType = CommandType.StoredProcedure
    //I try this ....
    cmd.Parameters.Add("@id", SqlDbType.Int).Value = DataList1.FindControl("IdLabel").ToString()
    cmd.Parameters.Add("@Comments", SqlDbType.NVarChar).Value = DataList1.FindControl("TextBoxComments").ToString()

    cmd.ExecuteNonQuery()
End Sub

I get an error like this: “The object reference is not definied to an object instance”

How can I catch the value from the label IdLabel and TextBoxComments in this situation?

  • 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-28T04:39:02+00:00Added an answer on May 28, 2026 at 4:39 am

    You should handle the DataList’s ItemCommand instead of the Button’s Command.

    Then you can find your controls with e.Item.FindControl:

    Private Sub DataList1_ItemCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) _
        Handles DataList1.ItemCommand
        If e.CommandName = "add" Then
            Dim IdLabel = DirectCast(e.Item.FindControl("IdLabel"), Label)
            Dim TextBoxComments = DirectCast(e.Item.FindControl("TextBoxComments"), TextBox)
            ' ... '
        End If
    End Sub
    

    on aspx, remove your redundant Command-handler:

    <asp:button ID="btnAjouter" CommandName="add"  Text="Ajouter" runat="server" />
    

    If you want to use the Button’s Click-Event instead, that’s possible also.

    Protected Sub btnAjouter_Click(sender As Object, e As EventArgs)
        Dim container = DirectCast(DirectCast(sender, Control).NamingContainer, DataListItem)
        Dim IdLabel = DirectCast(container.FindControl("IdLabel"), Label)
        Dim TextBoxComments = DirectCast(container.FindControl("TextBoxComments"), TextBox)
        ' ... '
    End Sub
    

    on aspx, add the click-event handler to the button:

    <asp:button ID="btnAjouter" OnClick="btnAjouter_Click" Text="Ajouter" runat="server" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This my data list: <asp:DataList ID=DataList1 runat=server DataSourceID=SqlDataSource1 RepeatLayout=Flow> <ItemTemplate> Titre: <asp:Label ID=TitreLabel runat=server
I have a datalist like this: <asp:DataList ID=dl runat=server Width=301px onitemcommand=dl_ItemCommand> <ItemTemplate> <table style=border:solid
Here is my DataList: <asp:DataList id=DataList Visible=false RepeatDirection=Horizontal Width=100% HorizontalAlign=Justify RepeatLayout=Flow runat=server> [Contents Removed]
I have written this datalist : <div class=story runat=server> <asp:DataList ID=DataList2 runat=server Height=16px Width=412px>
I have a DataList like below: <asp:DataList runat=server ID=myDataList> <ItemTemplate> <uc:MyControl ID=id1 runat=server PublicProperty='<%#
i have a datalist in my aspx like this: <asp:DataList ID=dlSubs runat=server CellPadding=0 CellSpacing=5
I have the following itemTemplate in my datalist <ItemTemplate> <asp:LinkButton ID=LinkButton1 CommandName=Select autopostback=True runat=server>'<%#
I have a DataList like so: <asp:DataList ID=dlMyList runat=server RepeatColumns=5 RepeatDirection=Horizontal CellSpacing=5 > <ItemTemplate>
This is my bare DataList definition :- <asp:DataList runat=server ID=dtltrial ondeletecommand=dtltrial_DeleteCommand DataKeyField=PhotoId > </asp:DataList>
I have a simple usercontrol, with a datalist, and checkboxes inside. <asp:DataList ID=DataListDroits runat=server

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.