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

  • Home
  • SEARCH
  • 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 8558375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:47:51+00:00 2026-06-11T15:47:51+00:00

Im trying to make my first linq connection to a gridview, (im not using

  • 0

Im trying to make my first linq connection to a gridview, (im not using linqdatasource) and i get the records fine to my gridview.
But my AddNewTask, UpdateTask, And DeleteTask gives me and error about my Me.txtxxxx.text or Me.lblxxxx.text is not a part of my gridview.
But the labels and textboxs are a part of my gridview.

Can someone help/guide me, what to do, im new to this linq, but have read alot of tutorials, but cant find any fix for my problem.

Code_Behind

Imports System.Data.Linq

Partial Class gridview
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        Call linqdb()
    End If
End Sub

Protected Sub linqdb()
    Using db As New ThedatabaseconnectionDataContext()
        Dim tblTest As Table(Of testtable) = db.GetTable(Of testtable)()
        Me.GridView1.DataSource = tblTest
        Me.GridView1.DataBind()
    End Using
End Sub

Protected Sub AddNewTask(ByVal sender As Object, ByVal e As EventArgs)
    Using db As New ThedatabaseconnectionDataContext()
        Try
            Dim tbltest As Table(Of testtable) = db.GetTable(Of testtable)()
            Dim rtest As testtable = New testtable With {.test_cat = Me.txttestcat.Text, .test_info = Me.txttestinfo.Text, .test_number = Me.txttestnumber.Text, .test_datetime = Me.txttestdate.Text}
            tbltest.InsertOnSubmit(rtest)
            db.SubmitChanges()
            'Me.lblMsg.Text = "Added Successfully"
        Catch ex As Exception
            'Me.lblMsg.Text = ex.Message
        End Try
    End Using
End Sub

Protected Sub EditTask(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
    GridView1.EditIndex = e.NewEditIndex
    linqdb()
End Sub

Protected Sub CancelEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
    GridView1.EditIndex = -1
    linqdb()
End Sub

Protected Sub UpdateTask(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    Using db As New ThedatabaseconnectionDataContext()
        Try
            Dim tbltest As Table(Of testtable) = db.GetTable(Of testtable)()
            Dim objtest As testtable = tbltest.SingleOrDefault(Function(p) p.test_id = Me.txttestid.Text)
            If objtest IsNot Nothing Then
                objtest.test_cat = Me.txttestcat.Text
                objtest.test_info = Me.txttestinfo.Text
                objtest.test_number = Me.txttestnumber.Text
                objtest.test_datetime = Me.txttestdate.Text
                db.SubmitChanges()
                ' Me.lblMsg.Text = "Updated Successfully"
            Else
                'Me.lblMsg.Text = "Employee not found"
            End If
        Catch ex As Exception
            'Me.lblMsg.Text = ex.Message
        End Try
    End Using
End Sub

Protected Sub DeleteTask(ByVal sender As Object, ByVal e As EventArgs)
    Using db As New ThedatabaseconnectionDataContext()
        Try
            Dim tbltest As Table(Of testtable) = db.GetTable(Of testtable)()
            Dim objtest As testtable = tbltest.SingleOrDefault(Function(p) p.test_id = Me.lbltestid.text)
            If objtest IsNot Nothing Then
                tbltest.DeleteOnSubmit(objtest)
                db.SubmitChanges()
                'Me.lblMsg.Text = "Deleted Successfully"
            Else
                'Me.lblMsg.Text = "Employee not found"
            End If
        Catch ex As Exception
            'Me.lblMsg.Text = ex.Message
        End Try
    End Using
End Sub
End Class

Main_Code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="gridview.aspx.vb" Inherits="gridview" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate> 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" 
        CellPadding="4" DataKeyNames="test_id" ForeColor="Black" GridLines="Horizontal" ShowFooter="true" 
        onrowediting="EditTask" onrowupdating="UpdateTask"  onrowcancelingedit="CancelEdit">
    <Columns>
        <asp:TemplateField ItemStyle-Width="30px" HeaderText="test_id">
            <ItemTemplate>
                <asp:Label ID="lbltestid" runat="server" Text='<%# Eval("test_id")%>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-Width="100px" HeaderText="test_cat">
            <ItemTemplate>
                <asp:Label ID="lbltestcat" runat="server" Text='<%# Eval("test_cat")%>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txttestcat" runat="server" Text='<%# Eval("test_cat")%>'></asp:TextBox>
            </EditItemTemplate> 
            <FooterTemplate>
                <asp:TextBox ID="txttestcat" runat="server"></asp:TextBox>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-Width="150px" HeaderText="test_info">
            <ItemTemplate>
                <asp:Label ID="lbltestinfo" runat="server" Text='<%# Eval("test_info")%>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txttestinfo" runat="server" Text='<%# Eval("test_info")%>'></asp:TextBox>
            </EditItemTemplate> 
            <FooterTemplate>
                <asp:TextBox ID="txttestinfo" runat="server"></asp:TextBox>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-Width="150px" HeaderText="test_number">
            <ItemTemplate>
                <asp:Label ID="lbltestnumber" runat="server" Text='<%# Eval("test_number")%>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txttestnumber" runat="server" Text='<%# Eval("test_number")%>'></asp:TextBox>
            </EditItemTemplate> 
            <FooterTemplate>
                <asp:TextBox ID="txttestnumber" runat="server"></asp:TextBox>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-Width="150px" HeaderText="test_date">
            <ItemTemplate>
                <asp:Label ID="lbltestdate" runat="server" Text='<%# Eval("test_datetime")%>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txttestdate" runat="server" Text='<%# Eval("test_datetime")%>'></asp:TextBox>
            </EditItemTemplate> 
            <FooterTemplate>
                <asp:TextBox ID="txttestdate" runat="server"></asp:TextBox>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="lnkRemove" runat="server" CommandArgument='<%# Eval("test_id")%>' OnClientClick="return confirm('Do you want to delete?')" Text="Delete" OnClick="DeleteTask"></asp:LinkButton>
            </ItemTemplate>
            <FooterTemplate>
                <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="AddNewTask" />
            </FooterTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowEditButton="True" />
    </Columns>
    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F7F7F7" />
    <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
    <SortedDescendingCellStyle BackColor="#E5E5E5" />
    <SortedDescendingHeaderStyle BackColor="#242121" />
    </asp:GridView>
</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="GridView1" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

testtableRecords.vb

Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Data.Linq.Mapping

<Table(Name:="testtablerecords")> _
Public Class testtableRecords
'DB Fieldname and type = new name _name..
Private _testId As Integer
<Column(IsPrimaryKey:=True)> _
Public Property test_id() As Integer
    Get
        Return _testId
    End Get

    Set(ByVal value As Integer)
        _testId = value
    End Set
End Property

'DB Fieldname and type = new name _name..
Private _testCat As String
<Column()> _
Public Property test_cat() As String
    Get
        Return _testCat
    End Get

    Set(ByVal value As String)
        _testCat = value
    End Set
End Property

'DB Fieldname and type = new name _name..
Private _testInfo As String
<Column()> _
Public Property test_info() As String
    Get
        Return _testInfo
    End Get

    Set(ByVal value As String)
        _testInfo = value
    End Set
End Property

'DB Fieldname and type = new name _name..
Private _testNumbers As Integer
<Column()> _
Public Property test_numbers() As Integer
    Get
        Return _testNumbers
    End Get

    Set(ByVal value As Integer)
        _testNumbers = value
    End Set
End Property

'DB Fieldname and type = new name _name..
Private _testDate As Date
<Column()> _
Public Property test_datetime() As Date
    Get
        Return _testDate
    End Get

    Set(ByVal value As Date)
        _testDate = value
    End Set
End Property

End Class
  • 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-11T15:47:52+00:00Added an answer on June 11, 2026 at 3:47 pm

    The problem is that txttestcat, txttestinfo et al. are not properties of your class gridview. They are the IDs of objects deep in the object hierarchy of the page, specifically that of GridView1.

    To access them, you need to use the FindControl method of the GridViewRow. I’m working from memory, here, but if you replace Me.txttestcat.Text with

    CType(e.Row.FindControl("txttestcat"),TextBox).Text
    

    … and convert the other lines similarly, you should be fine.

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

Sidebar

Related Questions

I'm trying to make my first application using Objective C + Core Data, but
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
I am trying to make my first app using XNA, and I am having
I am trying to make my first AJAX Control and I get error. I
I am trying to make a Linq to Entities Query working but I can't
I'm trying to test my code using EntityFramework code first. In order to make
I'm writing a Function that pulls Records from a DataBase using LINQ to get
I'm trying to get a paged query to work properly using LINQ and NHibernate.
Im trying to make my first app with eclipse and phonegap. But when I
I'm trying to make my first chrome extension here.It's a sticky note board. 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.