Solved

DataGrid TextBox Question

Posted on 2004-09-27
6
208 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

17 Experts available now in Live!

Get 1:1 Help Now