Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have an editable datagrid - in edit mode uses a couple of dropdownlists

and text boxes for changes. Once these have been completed I want the datagrid to be reloaded with the changes in place. The datagrid functions correctly up until doitemupdate is called.

 

When doitemupdate is called I want the dataset that is bound to the datagrid to reflect the changes.

 

On loading the page the following error occurs: (the error is thrown by the first line of doitemupdate shown below)

 

__________________________

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 176: dsTeamPlayer.AcceptChanges()

__________________________

 

Here is the relevant code:

 

Public sKey as string

Public MatchDataID as string

Public dsTeamPlayer As Dataset

Public dsCopy As DataSet

Public tpDataSet as Dataset

 

Public Sub Page_Load()

If Not Page.IsPostback Then

BindData

End If

End Sub

 

 

Public sub BindData()

MatchDataID = Session("MatchDataID")

sKey = Session("TeamID")

Dim oConnect As New OleDbConnection(ConfigurationSettings.AppSettings("connString"))

Dim oDR As OleDbDataAdapter = New OleDbDataAdapter

oDR.SelectCommand = New OleDbCommand("spTeamLineUp" , oConnect)

oDR.SelectCommand.CommandType = CommandType.StoredProcedure

Dim oParam As OleDbParameter = oDR.SelectCommand.Parameters.Add("@ParamID", OleDbType.Integer)

oParam.Value = sKey

oParam.Direction = ParameterDirection.Input

dim dsTeamPlayer As Dataset = New Dataset()

oDR.MissingSchemaAction = MissingSchemaAction.AddWithKey

oDR.Fill(dsTeamPlayer, "LastTeamPlayers")

dgr1.DataSource = dsTeamPlayer.Tables("LastTeamPlayers")

dgr1.DataBind()

End Sub

 

 

Sub DoItemEdit(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)

dgr1.EditItemIndex = CInt(E.Item.ItemIndex)

BindData

End Sub

 

Sub DoItemUpdate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

dsTeamPlayer.AcceptChanges()

dgr1.DataSource = dsTeamPlayer.Tables("LastTeamPlayers")

dgr1.DataBind()

End Sub

 

 

The datagrid:

 

<asp:DataGrid id="dgr1" runat="server"

DataKeyField="PlayerID"

OnEditCommand="DoItemEdit"

OnUpdateCommand="DoItemUpdate"

OnCancelCommand="DoItemCancel">

<Columns>

<asp:TemplateColumn HeaderText="Number">

<ItemTemplate>

<%# Container.DataItem("PNumber") %>

</ItemTemplate>

<EditItemTemplate>

<asp:TextBox Columns="8" id="PlayerNumber"

runat="server"

Text='<%# Container.DataItem("PNumber") %>' />

</EditItemTemplate>

</asp:TemplateColumn>

 

<asp:TemplateColumn HeaderText="Player">

<ItemTemplate>

<%# Container.DataItem("PlayerName") %>

</ItemTemplate>

<EditItemTemplate>

<asp:Label runat="server" id="PlayerID" Visible="False"

Text='<%# DataBinder.Eval(Container.DataItem, "PlayerID") %>'/>

<asp:DropDownList id=ddl1 runat="server" datavaluefield="PlayerID"

datatextfield="PlayerName" DataSource="<%# GetTeamPlayers %>">

</asp:DropDownList>

</EditItemTemplate>

</asp:TemplateColumn>

 

<asp:TemplateColumn HeaderText="Position">

<ItemTemplate>

<%# Container.DataItem("TPosition") %>

</ItemTemplate>

<EditItemTemplate>

<asp:Label runat="server"

id="TPositionID"

Visible="False"

Text='<%# DataBinder.Eval(Container.DataItem, "TPositionID") %>'/>

<asp:DropDownList id=ddl2 runat="server" datavaluefield="TPositionID"

datatextfield="TPosition" DataSource="<%# GetTeamPositions %>">

</asp:DropDownList>

</EditItemTemplate>

</asp:TemplateColumn>

 

<asp:TemplateColumn HeaderText="Goals">

<ItemTemplate>

<asp:Label Columns="8" id="GoalsScored"

runat="server"

Text='' />

</ItemTemplate>

<EditItemTemplate>

<asp:TextBox Columns="8" id="GoalsScored"

runat="server"

Text='' />

</EditItemTemplate>

</asp:TemplateColumn>

 

<asp:EditCommandColumn EditText="Edit"

CancelText="Cancel" UpdateText="Update" />

</Columns>

</asp:datagrid>

Posted

Object reference not set to an instance of an object

 

This did not make any difference. I think it is related to the sub:

 

Sub DoItemUpdate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

dsTeamPlayer.AcceptChanges()

dgr1.DataSource = dsTeamPlayer.Tables("LastTeamPlayers")

dgr1.DataBind()

End Sub

 

But I cannot get my head round it.

 

Thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...