Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Datagrid Editcommand dropdownlist problem

Author  Topic 

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2006-04-24 : 16:40:52
I'm getting the following error:
Type is neither a DataColumn nor a DataRelation for table Table

My table, "Activity_Types", has a PK field of "Type" which is an navarchar(100). It'll be a small table...no more than 10 records. That's the only field other than a smalldatetime field to show when the record was created.

My HTML is:

<asp:TemplateColumn HeaderText="Type">
<HeaderStyle Width="55px"></HeaderStyle>
<ItemTemplate>
<asp:Label id="Label27" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Activity Type") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlType" width="55px" style="Z-INDEX: 133" runat="server" DataValueField="Type" DataTextField="Type"
datasource="<%# GetTypes() %>"

SelectedIndex='<%# GetSelectedIndex(Container.DataItem("Type")) %>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

The code behind is:

Function GetTypes() As DataSet
Dim sCon1 As New SqlConnection
sCon1.ConnectionString = Session("DBDDL")
sCon1.Open()
Dim strSQLType As String = "usp_ActTypes"
Dim cmd As New SqlCommand(strSQLType, sCon1)
cmd.CommandType = CommandType.StoredProcedure

'Create the DataAdapter
Dim DA As New SqlDataAdapter
DA.SelectCommand = cmd

'Populate the DataSet and the connection
DA.Fill(ddlDataSet, "Activity_Types")
sCon1.Close()

Return ddlDataSet
End Function

Function GetSelectedIndex(ByVal ActVal As String) As String
'Loop through the dataset ddlDataSet
Dim iLoop As Integer
Dim dt As DataTable = ddlDataSet.Tables("Activity_Types")
For iLoop = 0 To dt.Rows.Count - 1
If ActVal = dt.Rows(iLoop)("Type").ToString() Then
Return iLoop
End If
Next iLoop
End Function
Private Sub DGActivities_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DGActivities.EditCommand
DGActivities.Columns(1).Visible = False
DGActivities.EditItemIndex = e.Item.ItemIndex
'First build the ddl for Type
Call BuildDGActivities()
End Sub

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2006-04-24 : 16:52:46
I found the issue, and the code should be:
SelectedIndex='<%# GetSelectedIndex(Container.DataItem("Activity Type")) %>'

I had "Type" in there when there's no such data when the grid is built.
Go to Top of Page
   

- Advertisement -