Solved

DataGrid TextBox Question

Posted on 2004-09-27
6
203 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now