Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 July 17th, 2012, 11:33 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile Only admin be able to create albums for users

Hi Imar,
My requirement is that only admin can create albums and put images in those albums for a specific user.
So when user loges in website he sees the updated albums.

So where should I modify the code so that only admin be able to add albums for a specific user(he needs to select user for whom he is creating album and putting images in that album)

Many thanks
 
Old July 18th, 2012, 04:22 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 there,

You can follow the same pattterns as described in Chapter 16 to protect the Management folder,

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 20th, 2012, 01:51 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Quote:
You can follow the same pattterns as described in Chapter 16 to protect the Management folder,
HI, I am saying that admin should be able to create albums for other users, and not the user should create albums for themselves.
So, in the album section admin should choose a user for whom he is creating album.

Many thanks
 
Old July 21st, 2012, 03:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I know, and as I suggested, most of what you need is explained in detail in the book. What you might be missing is getting a list of users which you can do using GetAllUsers.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 22nd, 2012, 09:43 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

got it working.
thanks
 
Old July 22nd, 2012, 10:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Good to hear. Would you mind sharing how, so others can benefit from your experiments?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 22nd, 2012, 03:20 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

It is my pleasure, and makes me feel Honorable.

1. I replaced column UserName to UserId (uniqueidentifier type) first and updated data model(.edmx) file.

2. I moved the NewPhotoAlbum.aspx(.cs) page(s) to Management folder so that only admin or members being in Managers role can add new album (according my need).

2. I added a template field in DetailsView1 and added dropdownlist, and connected it through SqlDataSource like below
Code:
 <asp:TemplateField HeaderText="User Name">
                <InsertItemTemplate>
                <asp:DropDownList ID="ddlUsers" runat="server" DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserId" 
                        SelectedValue='<%# Bind("UserId") %>'>
                </asp:DropDownList>
                </InsertItemTemplate>
                </asp:TemplateField>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT UserId,UserName FROM [aspnet_Users]"></asp:SqlDataSource>
Here connection string is ConnectionString which is associated with ASPNETDB database as I am using single database.

That's it, I do not require any code behind code to edit for this and hence I deleted EntityDataSource1_Inserting event.

Hope it may help someone else. I do not know if it is efficient code but yes it works.

Many thanks
The Following User Says Thank You to sophia For This Useful Post:
Imar (July 22nd, 2012)
 
Old August 12th, 2012, 05:01 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hi Imar,
I have one strange problem. I get this problem when I am either updating or deleting record from Template enabled Gridview with EntityDataSource.

error is "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries."

I found for it at google but solutions seems entire different approach.

When I use gridview with GenerateAutoColumn=False then it works fine, but when I used Template fields then it is giving error...

My code is below..

Code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="false"
        AllowSorting="True" DataSourceID="EntityDataSource1">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ItemStyle-Width="100px" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ItemStyle-Width="200px" />
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" ItemStyle-Width="300px" />
            
            <asp:TemplateField HeaderText="User Name">
                <ItemTemplate>
                    <asp:Label ID="lblUsers" runat="server" Text='<%# GetUserName(Eval("UserId")) %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                <asp:DropDownList ID="ddlUsers" runat="server" DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserId"
                        SelectedValue='<%# Bind("UserId") %>'>
                </asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

    <asp:EntityDataSource ID="EntityDataSource1" runat="server"
        ConnectionString="name=ASPNETDBEntities"
        DefaultContainerName="ASPNETDBEntities" EnableDelete="True"
        EnableFlattening="False" EnableInsert="True" EnableUpdate="True"
        EntitySetName="Plots">
    </asp:EntityDataSource>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT UserId,UserName FROM [aspnet_Users]"></asp:SqlDataSource>
And code behind is

Code:
protected string GetUserName(object userid)
    {
        string userName = (string)Membership.GetUser(userid).UserName;

        return userName;
    }
please tell me what is wrong with code???
 
Old August 12th, 2012, 11:38 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 there,

How is this related to the original post, or even to my book? I think it's better to start a new thread for a new topic, and in this case, probably in the general ASP.NET category as well.

That said, maybe you're missing primary key information? Have you tried setting DataKeyNames on the GridView to the primary key of your entity?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 13th, 2012, 01:52 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Quote:
Have you tried setting DataKeyNames on the GridView to the primary key of your entity
Thanks, it worked now...

Quote:
I think it's better to start a new thread for a new topic, and in this case, probably in the general ASP.NET category as well.
I did, but did not get reply.

Quote:
How is this related to the original post, or even to my book?
Not really related to book but I was working on this module as explained in this thread, and when I tried to modified it then I thought that there might be some issues which I was not able to negotiate at that time...

Many thanks for your reply, it solved problem....

Last edited by sophia; August 13th, 2012 at 02:21 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create Photo Gallery with admin Panel ? Abhishek Kumar ASP.NET 4 General Discussion 1 September 26th, 2011 03:26 AM
One img at 2 different albums Oshrib BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 May 8th, 2011 03:00 PM
All Photo Albums page cbspira BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 January 10th, 2009 08:09 AM
Adding another field to the create user admin tool Shell84 ASP.NET 2.0 Basics 3 February 27th, 2006 05:34 PM





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