Hi all,
Wondering if someone can help with a nagging problem I am having using
a GridView and an ObjectDataSource. I have a simple situation where I
am trying to delete a row from a table, but it doesn't seem to work at
all. Below is my ASP.NET page, and further below, my VB.NET method that
I am trying to call:
<div id="admin-faq" class="page">
<h2>Site FAQs (Frequently Asked Questions)</h2>
<asp:Panel ID="ListPanel" runat="server" Width="99%"
Visible="true">
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CellPadding="4" width="99%"
DataSourceID="ObjectDataSource1">
<EmptyDataTemplate>
Apparently, nobody asks any questions around here.
</EmptyDataTemplate>
<AlternatingRowStyle BackColor="#E0E0E0" />
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" DataFormatString="{0}" />
<asp:BoundField DataField="Question"
HeaderText="Question" SortExpression="Question" />
<asp:BoundField DataField="Answer"
HeaderText="Answer" SortExpression="Answer" />
<asp:BoundField DataField="Author"
HeaderText="Author" SortExpression="Author" />
<asp:CheckBoxField DataField="IsPublic"
HeaderText="IsPublic" SortExpression="IsPublic" />
</Columns>
</asp:GridView>
</asp:Panel>
</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="System.Guid" SelectMethod="GetFaqs"
TypeName="FaqManager" DeleteMethod="RemoveFaq">
<DeleteParameters>
<asp:Parameter Name="id" Type="Object" />
</DeleteParameters>
</asp:ObjectDataSource>
Public NotInheritable Class FaqManager
' Other methods left out, for clarity.
Public Shared Sub RemoveFaq(ByVal id As Guid)
Using connection As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("blcamp").ConnectionString)
Using command As New SqlCommand("RemoveFaq", connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New SqlParameter("@FaqID", id))
connection.Open()
command.ExecuteNonQuery()
End Using
End Using
End Sub
Public Shared Function GetFaqs() As Generic.List(Of Faq)
Using connection As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("blcamp").ConnectionString)
Using command As New SqlCommand("GetFaqs", connection)
command.CommandType = CommandType.StoredProcedure
Dim filter As Boolean = Not
(HttpContext.Current.User.IsInRole("Friends") Or
HttpContext.Current.User.IsInRole("Administrators" ))
command.Parameters.Add(New SqlParameter("@IsPublic",
filter))
connection.Open()
Dim list As New Generic.List(Of Faq)()
Using reader As SqlDataReader = command.ExecuteReader()
Do While (reader.Read())
Dim temp As New Faq(CType(reader("FaqID"),
Guid), CType(reader("Question"), String), CType(reader("Answer"),
String), CType(reader("Author"), String), CType(reader("IsPublic"),
Boolean))
list.Add(temp)
Loop
End Using
Return list
End Using
End Using
End Function
End Class
When I try to run the above code as is, the RemoveFaq method executes,
but the id parameter receives a value of <nothing>. Notice that
currently, the GridView has no DataKeyNames attribute set. If I try to
set it to Id, which is the primary key for my data as well as the
Delete Parameter, I get the following exception:
Could not find a property named 'id' on the type specified by the
DataObjectTypeName property in ObjectDataSource 'ObjectDataSource1'.
Does anyone out there know what I may be doing wrong here? Any help
would really be appreciated. Thanks much,
Barry L. Camp 1 8481
Barry,
You have to set the DataKeyName property in the GridView and delete the
DataObjectTypeName in the ObjectDataSource (that property is to use
custom objects as the parameter to the Delete method, and in your case
you're using a guid so that does not apply).
Also, delete the Type="Object" from the DeleteParameter.
Hope it helps,
Manuel Abadia http://www.manuelabadia.com
Barry L. Camp wrote:
Hi all,
Wondering if someone can help with a nagging problem I am having using
a GridView and an ObjectDataSource. I have a simple situation where I
am trying to delete a row from a table, but it doesn't seem to work at
all. Below is my ASP.NET page, and further below, my VB.NET method that
I am trying to call:
<div id="admin-faq" class="page">
<h2>Site FAQs (Frequently Asked Questions)</h2>
<asp:Panel ID="ListPanel" runat="server" Width="99%"
Visible="true">
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CellPadding="4" width="99%"
DataSourceID="ObjectDataSource1">
<EmptyDataTemplate>
Apparently, nobody asks any questions around here.
</EmptyDataTemplate>
<AlternatingRowStyle BackColor="#E0E0E0" />
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" DataFormatString="{0}" />
<asp:BoundField DataField="Question"
HeaderText="Question" SortExpression="Question" />
<asp:BoundField DataField="Answer"
HeaderText="Answer" SortExpression="Answer" />
<asp:BoundField DataField="Author"
HeaderText="Author" SortExpression="Author" />
<asp:CheckBoxField DataField="IsPublic"
HeaderText="IsPublic" SortExpression="IsPublic" />
</Columns>
</asp:GridView>
</asp:Panel>
</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="System.Guid" SelectMethod="GetFaqs"
TypeName="FaqManager" DeleteMethod="RemoveFaq">
<DeleteParameters>
<asp:Parameter Name="id" Type="Object" />
</DeleteParameters>
</asp:ObjectDataSource>
Public NotInheritable Class FaqManager
' Other methods left out, for clarity.
Public Shared Sub RemoveFaq(ByVal id As Guid)
Using connection As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("blcamp").ConnectionString)
Using command As New SqlCommand("RemoveFaq", connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New SqlParameter("@FaqID", id))
connection.Open()
command.ExecuteNonQuery()
End Using
End Using
End Sub
Public Shared Function GetFaqs() As Generic.List(Of Faq)
Using connection As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("blcamp").ConnectionString)
Using command As New SqlCommand("GetFaqs", connection)
command.CommandType = CommandType.StoredProcedure
Dim filter As Boolean = Not
(HttpContext.Current.User.IsInRole("Friends") Or
HttpContext.Current.User.IsInRole("Administrators" ))
command.Parameters.Add(New SqlParameter("@IsPublic",
filter))
connection.Open()
Dim list As New Generic.List(Of Faq)()
Using reader As SqlDataReader = command.ExecuteReader()
Do While (reader.Read())
Dim temp As New Faq(CType(reader("FaqID"),
Guid), CType(reader("Question"), String), CType(reader("Answer"),
String), CType(reader("Author"), String), CType(reader("IsPublic"),
Boolean))
list.Add(temp)
Loop
End Using
Return list
End Using
End Using
End Function
End Class
When I try to run the above code as is, the RemoveFaq method executes,
but the id parameter receives a value of <nothing>. Notice that
currently, the GridView has no DataKeyNames attribute set. If I try to
set it to Id, which is the primary key for my data as well as the
Delete Parameter, I get the following exception:
Could not find a property named 'id' on the type specified by the
DataObjectTypeName property in ObjectDataSource 'ObjectDataSource1'.
Does anyone out there know what I may be doing wrong here? Any help
would really be appreciated. Thanks much,
Barry L. Camp
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kjetil Klaussen |
last post by:
Hi,
I’m having some troubles trying to bind my dataset to a GridView control
through an ObjectDataSource control. The binding works fine for regular
columns in my dataset, but I can’t seem...
|
by: David Hubbard |
last post by:
I am using a GridView to display a set of objects that have a parent-child
relationship. Each object, MyBO, has
an ID property that is used to get the children of that object.
class MyBO
{
...
|
by: Jürgen Bayer |
last post by:
Hi,
I just tried out the ObjectDataSource of ASP.NET 2.0. A simple application
works with a GridView bound to an ObjectDataSource. The ObjectDataSource is
set to a (factory) class...
|
by: tarscher |
last post by:
Hi all,
I have a grid that contains 7 columns from 3 tables (3 unique keys, 4
normal fields). I show this 7 columns on the gridview. I now want to
add edit and delete functionality. This should...
|
by: Steve |
last post by:
I have a gridview which uses an objectdatasource for its select and
delete.
The delete command uses the function below. The delete itself works but
the extra logic which requires parameters...
|
by: Greg Lyles |
last post by:
Hi all,
I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.
In a nutshell, I'm stuck on trying to...
|
by: pargat.singh |
last post by:
I want to add delete button to grid view and pass all the clicked row
parameters. Can someone please tell me how can i do this? Below are my
codes.
Thanks in advance.
<asp:GridView...
|
by: rote |
last post by:
Hi Guys,
I have a simple Edit,Update Gridview and i'm using ObjectDatasource
with dataset generated and TableAdapters
I can do an update no problem.But can't get my delete to work.When i look
at...
|
by: Rote Rote |
last post by:
Hi Guys, I have a simple Edit,Update Gridview and i'm using
ObjectDatasource with dataset generated and TableAdapters I can do an
update no problem.
But can't get my delete to work. When i look at...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
| |