Solved

DataGrid TextBox Question

Posted on 2004-09-27
6
211 Views
Last Modified: 2010-04-23
Hi,

I have a datagrid on my form.  I also have the update/edit/cancel commands.  I want to simply allow a user to click the edit button, then when the textboxes are displayed they can input information and click update.  Here is my code...

Dim txt As String

txt = Convert.ToString(CType(e.Item.FindControl("DateSent"), TextBox).Text)
txtName.Text = txt

When I click update I get this error...

Object reference not set to an instance of an object.

Help!

Ryan
0
Comment
Question by:NeoTek
  • 4
  • 2
6 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12160248
I think I need a bit more code. When and where do you get the error, the code above in which event is it handled ?
0
 
LVL 1

Author Comment

by:NeoTek
ID: 12160386
Hi,

This is the function the code is in...

Private Sub dgStatus_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgStatus.UpdateCommand

        Dim txt As String

        txt = Convert.ToString(CType(e.Item.FindControl("DateSent"), TextBox).Text)
        txtName.Text = txt

End Sub

I get the error when the user click on the 'Update' button on the datagrid.

The error is with the line...

txt = Convert.ToString(CType(e.Item.FindControl("DateSent"), TextBox).Text)

NeoTek
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 50 total points
ID: 12160495
And how is this event generated ? Because it seems that
e (System.Web.UI.WebControls.DataGridCommandEventArgs) is nothing
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:NeoTek
ID: 12161191
Hi,

A user goes to this form.  They click 'edit' on one of the rows in the datagrid.  They edit a text box and click update.  They get the error when they click update.

Ryan
0
 
LVL 1

Author Comment

by:NeoTek
ID: 12161531
I tried to do this...

txtName.Text = dgStatus.Items.Item(e.Item.ItemIndex).Cells(6).Text

That doesn't return the value in the textbox, it just returns blank, but this...

txtName.Text = dgStatus.Items.Item(e.Item.ItemIndex).Cells(4).Text

will return a value, but that field can't be edited...

Ryan
0
 
LVL 1

Author Comment

by:NeoTek
ID: 12168684
Hi,

I believe I solved my problem.  It looks like I was data binding on every page load, therefore the info was reset and the original data was being written to the database.  Thanks for your help.

Ryan
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Advice in Xamarin 21 96
Get Client IP on RDS - VB.NET 15 67
Import Data from Multiple Text Files in Excel 12 58
vb.net 1 month apart 11 35
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question