Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DataGrid TextBox Question

Posted on 2004-09-27
6
Medium Priority
?
219 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 200 total points
ID: 12160495
And how is this event generated ? Because it seems that
e (System.Web.UI.WebControls.DataGridCommandEventArgs) is nothing
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

824 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