Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 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
 
Old August 12th, 2007, 11:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

More or less: yes.

Search Google for a tool called Reflector by Lutz Roeder.

It allows you to look into the assemblies that make up the .NET framework, so you can see *exactly* how this works.

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 12th, 2007, 11:57 AM
Authorized User
 
Join Date: Aug 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Magi
Default

Thanks Imar.I will try.:)

------------------------------------------------------------------------
We learn from the history that we do not learn from the history
 
Old August 13th, 2007, 05:17 AM
Authorized User
 
Join Date: Aug 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Magi
Default

Imar , today I do another little experiment to try to find out what DataKeys is.
And I end up with even more confusion. My experiment is based on the previous one.
Just modify the DataKeyNames:

Code:
   <asp:GridView ID="gvwTest" runat="server"   OnRowDataBound ="gvwTest_RowDataBound" OnRowCreated ="gvwTest_RowCreated" 
            AutoGenerateColumns="False" DataKeyNames="ArticleID,AddedBy,Title" DataSourceID="SqlDataSource1"         AutoGenerateDeleteButton="True"  AutoGenerateEditButton="True" AutoGenerateSelectButton="True" OnRowDeleted="gvwTest_RowDeleted" OnRowDeleting="gvwTest_RowDeleting" OnRowEditing="gvwTest_RowEditing" OnRowUpdated="gvwTest_RowUpdated" OnRowUpdating="gvwTest_RowUpdating" OnSelectedIndexChanged="gvwTest_SelectedIndexChanged" >
            <Columns >
                <asp:BoundField DataField="ArticleID" HeaderText="ArticleID" InsertVisible="False"
                    ReadOnly="True" SortExpression="ArticleID" />       
                <asp:BoundField DataField="AddedBy" HeaderText="AddedBy" SortExpression="AddedBy" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />                
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT [ArticleID], [AddedBy], [Title FROM [tbh_Articles]" 
            DeleteCommand="DELETE FROM [tbh_Articles] WHERE [ArticleID] = @ArticleID" 
            InsertCommand="INSERT INTO [tbh_Articles] ([AddedBy], [Title) VALUES (@AddedBy, @Title)" 
            UpdateCommand="UPDATE [tbh_Articles] SET [AddedBy] = @AddedBy, [Title] = @Title WHERE [ArticleID] = @ArticleID"    OnUpdated="SqlDataSource1_Updated" OnUpdating="SqlDataSource1_Updating">
            <DeleteParameters>
                <asp:Parameter Name="ArticleID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="AddedBy" Type="String" />
                <asp:Parameter Name="Title" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="AddedBy" Type="String" />
                <asp:Parameter Name="Title" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>

if I do this change, I found that I can not Edit the record anyway.It will successful sumit,but the result is unchanged.
if I changed the DataKeyNames to DataKeyNames="ArticleID,AddedBy" ,then the Title is Updatable while the AddedBy is not! The same thing happen if I change it to DataKeyNames="ArticleID,Title" .This time the AddedBy is Updatable while the Title is not.
if I cross out the PrimerKey of the Article Table,that it the ArticleID,then it will give me a tuntime error for both Update and Delete operation.

I watch the GridViewUpdateEventArgs e in the gvwTest_RowUpdating event handler.And I find out something regular:
The e.Keys property is always the same with the GridView's DataKeys collection.
The e.NewValues property is all the retrieve field except the PrimerKey ArticleID.
The e.OldValues property is all the retrieve field except the DataKeyNames.

I suppose the fields in the DataKeyNames can not be changed.I am rather confused at what in fact the DataKeys is ?
Thanks.



------------------------------------------------------------------------
We learn from the history that we do not learn from the history
 
Old August 13th, 2007, 05:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

http://msdn2.microsoft.com/en-us/lib...akeynames.aspx
Quote:
quote:Gets or sets an array that contains the names of the primary key fields for the items displayed in a GridView control.
You should make the fields primary keys in the database as well (a composite key).

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 13th, 2007, 06:59 AM
Authorized User
 
Join Date: Aug 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Magi
Default

Thanks Imar.I have to admit I didn't search MSDN much.I think I will do it more often from now on
in order to make good use of it. It's a good place.

------------------------------------------------------------------------
We learn from the history that we do not learn from the history
 
Old August 14th, 2007, 03:41 AM
Authorized User
 
Join Date: Aug 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Magi
Default

Imar,these days I was trying to write a photo album by studying your PhotoAlbum in your instance result book.
in your book,you user DataList to show all the pictures in a specified photo collection.It's cool that
the DataList support Repeating Columns , but I want it to support paging so that it wound't span too long
if I have many photos in this collection and to also enhance the performance.However I found that the
DataList does't support paging and sorting. Then I turn to the GridView ,only to find that it does't
support Repeating Columns.How can I get both of them,that is a DataControl that support both paging and
Repeating Columns? Thanks.

------------------------------------------------------------------------
We learn from the history that we do not learn from the history
 
Old August 14th, 2007, 03:51 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Magi,

Can you please start a new thread for a new topic? Your last question isn't related to the original topic at all. Posting a new thread makes it much easier for everyone to find the right information.

Anyway, you can use paging with the DataList with a class called PagedDataSource. At page 294 of the book this is discussed in detail.

Alternatively, search Google for

custom paging SQL server

if you want to learn more about database paging.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 14th, 2007, 04:15 AM
Authorized User
 
Join Date: Aug 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Magi
Default

Thanks for your quick reply. I am sorry about that. I was used to post all the topic in one place
if I can got the answer from there. Now I know it's a bad habit. You are right,Posting a new
thread makes it much easier for everyone to find the right information. I want everyone to learn
something useful from my experience so that they can avoid it in advance or manage it much easyly.
Thanks for your remind. Also for your answer.:)

------------------------------------------------------------------------
We learn from the history that we do not learn from the history
 
Old August 14th, 2007, 04:18 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No problem....

And, you're welcome....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old November 18th, 2007, 05:34 PM
Authorized User
 
Join Date: Aug 2007
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello!
So is there any quick method or way to fix this problem in the Marco Code? If yes, why don,t you fellas post some kind of list of actions or whatever!?
I face it too now, but the long disscussion available in ths topic seems to me useless, koz I'm a begginer.

Thanx!






Similar Threads
Thread Thread Starter Forum Replies Last Post
F5 (Refresh) adds a new record after postback krainov BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 20th, 2007 10:10 AM
Browser Refresh vs. Regular Link kwilliams Classic ASP Basics 1 March 30th, 2006 09:10 PM
Insert new Record priority05 Classic ASP Databases 2 September 6th, 2004 12:26 PM
Insert new record ID levinho Classic ASP Databases 5 January 14th, 2004 12:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.