Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DataGrid TextBox Question

Posted on 2004-09-27
6
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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…

705 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