 |
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

November 20th, 2012, 09:30 AM
|
Registered User
|
|
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
DetailView Update not working.
Hi all, new member stuck so need some help please
I'm following page 410 - Beginning ASP.NET 3.5
DB Name
Columns: - id (PK, int, not null)
- name (varchar(50), null)
- address (varchar(50), null)
I can insert OK into the database
I can't update, when i try to do this and check the results, nothing has changed :(
My DetailsView page is displaying the record ok based on the query string parameter so ?id=2 and ?id=3 pull through different records fine.
Here is my code, all drap and drop:
Code:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Insert"
Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Commercial_db %>"
DeleteCommand="DELETE FROM [A_TEST_SCOTT] WHERE [id] = @id"
InsertCommand="INSERT INTO [A_TEST_SCOTT] ([id], [name], [address]) VALUES (@id, @name, @address)"
SelectCommand="SELECT [id], [name], [address] FROM [A_TEST_SCOTT] WHERE ([id] = @id)"
UpdateCommand="UPDATE [A_TEST_SCOTT] SET [name] = @name, [address] = @address WHERE [id] = @id">
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="address" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
Code Behind
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.Get("id") != null)
{
DetailsView1.DefaultMode = DetailsViewMode.Edit;
}
}
any advise appreciated
|

November 20th, 2012, 11:40 AM
|
Registered User
|
|
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok i think i may have figured out what wrong.
My code was in a Web User Control .ascx
When i tried again using a Web Form .aspx the update worked fine.
The problem is i'm using a CMS so can only use Web User Conrols... what can i do?
|

November 20th, 2012, 02:45 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
This should work in User Controls as well. Are you sure you're passing the correct query string parameter ("id") from the lost page to the edit page that contains the UC?
Imar
|

November 21st, 2012, 07:35 AM
|
Registered User
|
|
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Imar, thanks for taking the time to post back, and so quickly
I tried a little experiment
i have saved my DetailsView which does the displaying/editing/inserting in a control: dv.ascx
i have then created a webform.aspx and a webusercontrol.ascx - both of these files include the dv.ascx control
as before, inserting from both webform.aspx and webusercontrol.ascx works fine
when it comes to editing, only webform.aspx works, webusercontrol.ascx does nothing. This is strange given that they are both using the exact same code contained in dv.ascx
I take it there is probably some underlying conflict with the CMS i'm using.
Last edited by scott100; November 21st, 2012 at 07:44 AM..
|

November 21st, 2012, 02:23 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Try debugging the site and set a breakpoint in the code that looks at the Query string:
if (Request.QueryString.Get("id") != null)
Then put a watch on Request.QueryString.Get("id"). Maybe that's null? Or maybe the code in Page_Load doesn't fire at all?
Imar
|

March 30th, 2013, 03:54 AM
|
|
I try to update the detailview control. got this error messsage. ObjectDataSource 'odsDetail' could not find a non-generic method 'Update
|

March 30th, 2013, 09:47 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
How is this related to the original post? If I were you, I'd start a new thread, and supply lots more information and the current code you're working with.
Cheers,
Imar
|
|
 |