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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:48:09+00:00 2026-06-05T13:48:09+00:00

i have a datalist in which data from table detail are displayed and it

  • 0

i have a datalist in which data from table detail are displayed and it is working fine. now i need to insert some data of this datalist to another table detail2. i give a save button to each raw of the datalist so that on click of this save button particular data of that raw store to table detail2. bellow the design of my datalist .

         <asp:DataList ID="drecord" runat="server" Font-Bold="false" Font-Names="times new roman" Font-Size="Small" DataKeyField="id" RepeatColumns="1">

          <ItemTemplate>              
          <div><table>
             <tr><td><asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# GetImageURL(Eval("Pic")) %>' PostBackUrl='<%# Eval("id", "qrystng.aspx?id={0}") %>'/><br />
            <asp:LinkButton ID="Name1" runat="server" ForeColor="Blue" Text='<%#Container.DataItem("Name")%>'><br />
            </asp:LinkButton><asp:Label ID="id" runat="server" Text='<%#Container.DataItem("id")%>'></asp:Label></td>
            <td><asp:Button ID="insert" runat="server" BorderStyle="None" Font-Bold="true" Text="save" OnClick="saveinsert_click"/></td></tr>
            </table></div>                 
            </ItemTemplate>
 </asp:DataList>

and this onclick event saveinsert is for inserting data to table detail2.

  Sub saveinsert(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim cmd As New SqlCommand("insert into detail2(serial,id) values('" & fid & "',@rid)", con)
    cmd.Parameters.Add("@rid", SqlDbType.VarChar).Value = DirectCast(drecord.Controls(0).FindControl("id"), Label).Text
    con.Open()
    cmd.ExecuteNonQuery()
    con.Close()
  End sub

but when i click on the insert button it give errror as
“Object reference not set to an instance of an object.”
Exception Details : System.NullReferenceException: Object reference not set to an instance of an object.

and shows error on this line
” cmd.Parameters.Add(“@rid”, SqlDbType.VarChar).Value = DirectCast(drecord.Controls(0).FindControl(“id”), Label).Text “

the datalist displaying records correctly. i need to take the value of label “id” to store . i am not able to catch where i went wrong . help me with this

  • 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-06-05T13:48:11+00:00Added an answer on June 5, 2026 at 1:48 pm

    Use ItemCommand event of datalist:

    Protected Sub drecord_ItemCommand(source As Object, e As DataListCommandEventArgs)
        If e.CommandName = "CommabdName" Then
         Dim Label1 As Label =  DirectCast(e.item.FindControl("id"), Label)
         Dim labelText As string = Label1.Text
        //write your code here
        End If
    End Sub
    
         <asp:DataList ID="drecord" runat="server" Font-Bold="false" Font-Names="times new roman" Font-Size="Small" DataKeyField="id" RepeatColumns="1">
    
              <ItemTemplate>              
    ...................
                <td><asp:Button ID="insert" CommandName="CommabdName" runat="server" BorderStyle="None" Font-Bold="true" Text="save" />
    .........................               
                </ItemTemplate>
     </asp:DataList>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this XML file from which I'm grabbing all the data: <?xml version=1.0
I have made some progress with the DataList and UserControl this morning but I
I am using datalist to display data from the database,I have got three fields
I have one update panel inside which I have datalist. This update panel triggers
I have been given some 'reports' from another piece of software that contains data
I have file *.data, which include data in this order: 2.5,10,U1 3,4.5,U1 3,9,U1 3.5,5.5,U1
I have a number of pages which need to support exporting data to an
I have a datalist control which some controls(ex: button) are in it. I want
In my ASP.NET Web-form Project I have an Event which Export Data ( List<Profit>
I have the following code which is created with a datalist control: http://jsfiddle.net/vmE2E/1/ But

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.