I am getting an error...
I've got the template columns, and here's my code to
update:
=================================================
Sub dgCoordinator_Update(sender as Object, e as
DataGridCommandEventArgs)
'update database
'determine the value of the coordinator id column
Dim userID as Integer = e.Item.Cells(1).Text
'reference each textbox
'Dim uname as TextBox =
e.Item.Cells(2).Controls(0)
'Dim pword as TextBox =
e.Item.Cells(3).Controls(0)
'Dim lname as TextBox =
e.Item.Cells(4).Controls(0)
'Dim fname as TextBox =
e.Item.Cells(5).Controls(0)
'Dim email as TextBox =
e.Item.Cells(6).Controls(0)
'Dim phone as TextBox =
e.Item.Cells(7).Controls(0)
'Dim regcode as TextBox =
e.Item.Cells(8).Controls(0)
Dim uname as string =
CType(e.Item.FindControl("txtUsername"),textbox).Text
Dim pword as string =
CType(e.Item.FindControl("txtPassword"),textbox).Text
Dim lname as string =
CType(e.Item.FindControl("txtLastName"),textbox).Text
Dim fname as string =
CType(e.Item.FindControl("txtFirstName"),textbox).Text
Dim email as string =
CType(e.Item.FindControl("txtEmail"),textbox).Text
Dim phone as string =
CType(e.Item.FindControl("txtPhone"),textbox).Text
Dim regcode as string =
CType(e.Item.FindControl("txtRegionCode"),textbox).Text
UpdateCoordinator(userID, uname, pword, lname,
fname, email, phone, regcode)
dgCoordinator.EditItemIndex = -1
dgCoordinator.DataSource = GetCoordinator(lname,
fname)
dgCoordinator.DataBind()
Label1.Text = "Record has been updated."
End Sub
===========================================
But here's my error, what did I do wrong?
==================================================
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during
the execution of the current web request. Please
review the stack trace for more information about the
error and where it originated in the code.
Exception Details: System.NullReferenceException:
Object reference not set to an instance of an object.
Source Error:
Line 71:
Line 72:
Line 73: Dim uname as string =
CType(e.Item.FindControl("txtUsername"),textbox).Text
Line 74: Dim pword as string =
CType(e.Item.FindControl("txtPassword"),textbox).Text
Line 75: Dim lname as string =
CType(e.Item.FindControl("txtLastName"),textbox).Text
Source File: G:\10-01-04\editcoordinator2.aspx
Line: 73
Stack Trace:
[NullReferenceException: Object reference not set to
an instance of an object.]
ASP.editcoordinator2_aspx.dgCoordinator_Update(Object
sender, DataGridCommandEventArgs e) in
G:\10-01-04\editcoordinator2.aspx:73
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs
e) +83
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object
source, EventArgs e) +499
System.Web.UI.Control.RaiseBubbleEvent(Object
source, EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object
source, EventArgs e) +100
System.Web.UI.Control.RaiseBubbleEvent(Object
source, EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs
e) +94
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
postData) +138
System.Web.UI.Page.ProcessRequestMain() +1263
====================================================
--- Karthick Kumar <[EMAIL PROTECTED]>
wrote:
> OH, I think UID is your primary key, so leave it as
> databound and make it
> read only=true if you are displaying it in the
> datagrid..
>
> Karthick
>
>
> -----Original Message-----
> From: Anna Leon [mailto:[EMAIL PROTECTED]
> Sent: 01 October 2004 16:51
> To: [EMAIL PROTECTED]
> Subject: RE: [AspNetAnyQuestionIsOk] Datagrid Edit
>
> What about the uid? Change that to a template column
> too? Or can I leave it as a databound column?
>
> --- Karthick Kumar <[EMAIL PROTECTED]>
> wrote:
>
> > Hi,
> >
> >
> >
> > It is because you are passing the same values for
> > the two textboxes and you
> > are taking from the available datagrid [ see in
> > your code: Dim uname as
> > TextBox = e.Item.Cells(2).Controls(0) ]
> >
> > So better try the following:
> >
> >
> >
> > 1. In your datagrid, instead of Databound, have
> > it as template columns
> > like below:
> >
> >
> >
> > (Replace the DataItem.std with your column, for
> > example DataItem.Username
> > and id as DataItem.txtUsername etc.)
> >
> >
> >
> > ** Note: You got to do this for all the columns
> > which you want to edit **
> >
> >
> >
> > <asp:TemplateColumn HeaderText="Standard Time">
> >
> > <ItemTemplate>
> >
> > <asp:Label runat="server" Text='<%#
> > DataBinder.Eval(Container,
> > "DataItem.Std") %>'></asp:Label>
> >
> > </ItemTemplate>
> >
> > <EditItemTemplate>
> >
> > <asp:TextBox runat="server" id="txtStd" Text='<%#
> > DataBinder.Eval(Container,
> > "DataItem.Std") %>'></asp:TextBox>
> >
> > </EditItemTemplate>
> >
> > </asp:TemplateColumn>
> >
> >
> >
> > 2. And then get the entered updated value in
> your
> > code like this:
> >
> >
> >
> > Dim std As Integer =
> > CType(e.Item.FindControl("txtStd"),
> > TextBox).Text
> >
> >
> >
> > So in your case, it could be like this:
> >
> >
> >
> > Dim uname as string =
> > CType(e.Item.FindControl("txtUsername"),
> > textbox).text
> >
> >
> >
> > Try this and this will certainly work !!.
> >
> >
> >
> > Hth,
> >
> > Karthick
> >
> >
> >
> >
> >
> > [Non-text portions of this message have been
> > removed]
> >
> >
>
>
>
>
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/