| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools |
Rating:
|
|
|
|
| |
|
Eliyahu Goldin
Guest
Posts: n/a
|
User.Identity.Name will give you user name. What do you mean by UserId?
-- Eliyahu Goldin, Software Developer Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin http://usableasp.net "Jim" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... >I have created an insert FormView. There are three inputs to the database: > 1. RestarurantId - automatically done > 2. RestaurantUserId - Id of user that is logged in and inserts the record > 3. RestaruantInfo - text information > > The form below will insert the RestaurantId and the RestaurantInfo but for > the life of me, I can't figure how to get the UserId of the person logged > in. I have read the articles on aspnet.4guysfromrolla.com, but I can't > figure out how to make it work on my form. > > Can someone show me the code I need to put in to make this work. > I'm using DotNet 3.5 and SQL Server 2005. > > Thank you!!!! > > > ---- Start of page code --- > > <%@ Page Language="VB" %> > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > <script runat="server"> > > </script> > > <html xmlns="http://www.w3.org/1999/xhtml"> > <head runat="server"> > <title>Untitled Page</title> > </head> > <body> > <form id="form1" runat="server"> > <div> > > <asp:FormView ID="FormView1" runat="server" > DataKeyNames="RestaurantID" > DataSourceID="SqlDataSource1" DefaultMode="Insert"> > <InsertItemTemplate> > RestaurantUserId: > <asp:TextBox ID="RestaurantUserIdTextBox" runat="server" > Text='<%# Bind("RestaurantUserId") %>' /> > <br /> > RestaurantInfo: > <asp:TextBox ID="RestaurantInfoTextBox" runat="server" > Text='<%# Bind("RestaurantInfo") %>' /> > <br /> > <asp:LinkButton ID="InsertButton" runat="server" > CausesValidation="True" > CommandName="Insert" Text="Insert" /> > <asp:LinkButton ID="InsertCancelButton" > runat="server" > CausesValidation="False" CommandName="Cancel" > Text="Cancel" /> > </InsertItemTemplate> > <ItemTemplate> > RestaurantID: > <asp:Label ID="RestaurantIDLabel" runat="server" > Text='<%# Eval("RestaurantID") %>' /> > <br /> > RestaurantUserId: > <asp:Label ID="RestaurantUserIdLabel" runat="server" > Text='<%# Bind("RestaurantUserId") %>' /> > <br /> > RestaurantInfo: > <asp:Label ID="RestaurantInfoLabel" runat="server" > Text='<%# Bind("RestaurantInfo") %>' /> > <br /> > <asp:LinkButton ID="EditButton" runat="server" > CausesValidation="False" > CommandName="Edit" Text="Edit" /> > <asp:LinkButton ID="DeleteButton" runat="server" > CausesValidation="False" > CommandName="Delete" Text="Delete" /> > <asp:LinkButton ID="NewButton" runat="server" > CausesValidation="False" > CommandName="New" Text="New" /> > </ItemTemplate> > </asp:FormView> > <asp:SqlDataSource ID="SqlDataSource1" runat="server" > ConnectionString="<%$ ConnectionStrings:ConnectionString %>" > InsertCommand="INSERT INTO [ZCRestaurant] ([RestaurantUserId], > [RestaurantInfo]) VALUES (@RestaurantUserId, @RestaurantInfo)"> > <InsertParameters> > <asp:Parameter Name="RestaurantUserId" Type="String" /> > <asp:Parameter Name="RestaurantInfo" Type="String" /> > </InsertParameters> > </asp:SqlDataSource> > > </div> > </form> > </body> > </html> > > ---- End of page code --- > > |
|
||
|
||||
|
Jim
Guest
Posts: n/a
|
I want the UserID for the user that is stored in the dbo.aspnet_Users table
to be inserted. This will identify the user with the record. I don't know how to use the User.Identity.Name you listed. Can you show me in my code what to do? Thanks. "Eliyahu Goldin" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... > User.Identity.Name will give you user name. What do you mean by UserId? > > -- > Eliyahu Goldin, > Software Developer > Microsoft MVP [ASP.NET] > http://msmvps.com/blogs/egoldin > http://usableasp.net > > > "Jim" <(E-Mail Removed)> wrote in message > news:(E-Mail Removed)... >>I have created an insert FormView. There are three inputs to the >>database: >> 1. RestarurantId - automatically done >> 2. RestaurantUserId - Id of user that is logged in and inserts the record >> 3. RestaruantInfo - text information >> >> The form below will insert the RestaurantId and the RestaurantInfo but >> for the life of me, I can't figure how to get the UserId of the person >> logged in. I have read the articles on aspnet.4guysfromrolla.com, but I >> can't figure out how to make it work on my form. >> >> Can someone show me the code I need to put in to make this work. >> I'm using DotNet 3.5 and SQL Server 2005. >> >> Thank you!!!! >> >> >> ---- Start of page code --- >> >> <%@ Page Language="VB" %> >> >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> >> >> <script runat="server"> >> >> </script> >> >> <html xmlns="http://www.w3.org/1999/xhtml"> >> <head runat="server"> >> <title>Untitled Page</title> >> </head> >> <body> >> <form id="form1" runat="server"> >> <div> >> >> <asp:FormView ID="FormView1" runat="server" >> DataKeyNames="RestaurantID" >> DataSourceID="SqlDataSource1" DefaultMode="Insert"> >> <InsertItemTemplate> >> RestaurantUserId: >> <asp:TextBox ID="RestaurantUserIdTextBox" runat="server" >> Text='<%# Bind("RestaurantUserId") %>' /> >> <br /> >> RestaurantInfo: >> <asp:TextBox ID="RestaurantInfoTextBox" runat="server" >> Text='<%# Bind("RestaurantInfo") %>' /> >> <br /> >> <asp:LinkButton ID="InsertButton" runat="server" >> CausesValidation="True" >> CommandName="Insert" Text="Insert" /> >> <asp:LinkButton ID="InsertCancelButton" >> runat="server" >> CausesValidation="False" CommandName="Cancel" >> Text="Cancel" /> >> </InsertItemTemplate> >> <ItemTemplate> >> RestaurantID: >> <asp:Label ID="RestaurantIDLabel" runat="server" >> Text='<%# Eval("RestaurantID") %>' /> >> <br /> >> RestaurantUserId: >> <asp:Label ID="RestaurantUserIdLabel" runat="server" >> Text='<%# Bind("RestaurantUserId") %>' /> >> <br /> >> RestaurantInfo: >> <asp:Label ID="RestaurantInfoLabel" runat="server" >> Text='<%# Bind("RestaurantInfo") %>' /> >> <br /> >> <asp:LinkButton ID="EditButton" runat="server" >> CausesValidation="False" >> CommandName="Edit" Text="Edit" /> >> <asp:LinkButton ID="DeleteButton" runat="server" >> CausesValidation="False" >> CommandName="Delete" Text="Delete" /> >> <asp:LinkButton ID="NewButton" runat="server" >> CausesValidation="False" >> CommandName="New" Text="New" /> >> </ItemTemplate> >> </asp:FormView> >> <asp:SqlDataSource ID="SqlDataSource1" runat="server" >> ConnectionString="<%$ ConnectionStrings:ConnectionString %>" >> InsertCommand="INSERT INTO [ZCRestaurant] ([RestaurantUserId], >> [RestaurantInfo]) VALUES (@RestaurantUserId, @RestaurantInfo)"> >> <InsertParameters> >> <asp:Parameter Name="RestaurantUserId" Type="String" /> >> <asp:Parameter Name="RestaurantInfo" Type="String" /> >> </InsertParameters> >> </asp:SqlDataSource> >> >> </div> >> </form> >> </body> >> </html> >> >> ---- End of page code --- >> >> > > |
|
||
|
||||
|
Eliyahu Goldin
Guest
Posts: n/a
|
1.Add <asp:Parameter Name="@UserId" Type="String" /> to the
<InsertParameters> in the datasource and add UserId to the insert sql.. 2. Handle Inserting event for the datasource. In the event call User.Identity.Name to get user name and then Membership.GetUser (userName).ProviderUserKey to get user id. 3. In the same Inserting event, Locate the @UserId parameter in the insert parameter collection as e.Command.Parameters["@UserId"]. Set it's value to the user id obtained on step 2. -- Eliyahu Goldin, Software Developer Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin http://usableasp.net "Jim" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... >I want the UserID for the user that is stored in the dbo.aspnet_Users table >to be inserted. This will identify the user with the record. > I don't know how to use the User.Identity.Name you listed. Can you show > me in my code what to do? > Thanks. > > "Eliyahu Goldin" <(E-Mail Removed)> wrote in > message news:(E-Mail Removed)... >> User.Identity.Name will give you user name. What do you mean by UserId? >> >> -- >> Eliyahu Goldin, >> Software Developer >> Microsoft MVP [ASP.NET] >> http://msmvps.com/blogs/egoldin >> http://usableasp.net >> >> >> "Jim" <(E-Mail Removed)> wrote in message >> news:(E-Mail Removed)... >>>I have created an insert FormView. There are three inputs to the >>>database: >>> 1. RestarurantId - automatically done >>> 2. RestaurantUserId - Id of user that is logged in and inserts the >>> record >>> 3. RestaruantInfo - text information >>> >>> The form below will insert the RestaurantId and the RestaurantInfo but >>> for the life of me, I can't figure how to get the UserId of the person >>> logged in. I have read the articles on aspnet.4guysfromrolla.com, but I >>> can't figure out how to make it work on my form. >>> >>> Can someone show me the code I need to put in to make this work. >>> I'm using DotNet 3.5 and SQL Server 2005. >>> >>> Thank you!!!! >>> >>> >>> ---- Start of page code --- >>> >>> <%@ Page Language="VB" %> >>> >>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> >>> >>> <script runat="server"> >>> >>> </script> >>> >>> <html xmlns="http://www.w3.org/1999/xhtml"> >>> <head runat="server"> >>> <title>Untitled Page</title> >>> </head> >>> <body> >>> <form id="form1" runat="server"> >>> <div> >>> >>> <asp:FormView ID="FormView1" runat="server" >>> DataKeyNames="RestaurantID" >>> DataSourceID="SqlDataSource1" DefaultMode="Insert"> >>> <InsertItemTemplate> >>> RestaurantUserId: >>> <asp:TextBox ID="RestaurantUserIdTextBox" runat="server" >>> Text='<%# Bind("RestaurantUserId") %>' /> >>> <br /> >>> RestaurantInfo: >>> <asp:TextBox ID="RestaurantInfoTextBox" runat="server" >>> Text='<%# Bind("RestaurantInfo") %>' /> >>> <br /> >>> <asp:LinkButton ID="InsertButton" runat="server" >>> CausesValidation="True" >>> CommandName="Insert" Text="Insert" /> >>> <asp:LinkButton ID="InsertCancelButton" >>> runat="server" >>> CausesValidation="False" CommandName="Cancel" >>> Text="Cancel" /> >>> </InsertItemTemplate> >>> <ItemTemplate> >>> RestaurantID: >>> <asp:Label ID="RestaurantIDLabel" runat="server" >>> Text='<%# Eval("RestaurantID") %>' /> >>> <br /> >>> RestaurantUserId: >>> <asp:Label ID="RestaurantUserIdLabel" runat="server" >>> Text='<%# Bind("RestaurantUserId") %>' /> >>> <br /> >>> RestaurantInfo: >>> <asp:Label ID="RestaurantInfoLabel" runat="server" >>> Text='<%# Bind("RestaurantInfo") %>' /> >>> <br /> >>> <asp:LinkButton ID="EditButton" runat="server" >>> CausesValidation="False" >>> CommandName="Edit" Text="Edit" /> >>> <asp:LinkButton ID="DeleteButton" runat="server" >>> CausesValidation="False" >>> CommandName="Delete" Text="Delete" /> >>> <asp:LinkButton ID="NewButton" runat="server" >>> CausesValidation="False" >>> CommandName="New" Text="New" /> >>> </ItemTemplate> >>> </asp:FormView> >>> <asp:SqlDataSource ID="SqlDataSource1" runat="server" >>> ConnectionString="<%$ ConnectionStrings:ConnectionString %>" >>> InsertCommand="INSERT INTO [ZCRestaurant] >>> ([RestaurantUserId], [RestaurantInfo]) VALUES (@RestaurantUserId, >>> @RestaurantInfo)"> >>> <InsertParameters> >>> <asp:Parameter Name="RestaurantUserId" Type="String" /> >>> <asp:Parameter Name="RestaurantInfo" Type="String" /> >>> </InsertParameters> >>> </asp:SqlDataSource> >>> >>> </div> >>> </form> >>> </body> >>> </html> >>> >>> ---- End of page code --- >>> >>> >> >> > > |
|
||
|
||||
|
Jim
Guest
Posts: n/a
|
I understood number 1, but not 2 and 3. I'm thinkng 2 and 3 have to do with
the script and that I have no idea past what I wrote. Here is what I put in for all the code. Can you help with it from what you wrote. Thanks. .. -- Start of Code --- <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub FormView1_InsertButtonClick() SqlDataSource1.Insert() End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:FormView ID="FormView1" runat="server" DataKeyNames="RestaurantID" DataSourceID="SqlDataSource1" DefaultMode="Insert"> <InsertItemTemplate> RestaurantUserId: <asp:TextBox ID="RestaurantUserIdTextBox" runat="server" Text='<%# Bind("RestaurantUserId") %>' /> <br /> RestaurantInfo: <asp:TextBox ID="RestaurantInfoTextBox" runat="server" Text='<%# Bind("RestaurantInfo") %>' /> <br /> <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" /> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </InsertItemTemplate> <ItemTemplate> RestaurantID: <asp:Label ID="RestaurantIDLabel" runat="server" Text='<%# Eval("RestaurantID") %>' /> <br /> RestaurantUserId: <asp:Label ID="RestaurantUserIdLabel" runat="server" Text='<%# Bind("RestaurantUserId") %>' /> <br /> RestaurantInfo: <asp:Label ID="RestaurantInfoLabel" runat="server" Text='<%# Bind("RestaurantInfo") %>' /> <br /> <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" /> <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" /> <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" /> </ItemTemplate> </asp:FormView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" InsertCommand="INSERT INTO [ZCRestaurant] ([RestaurantUserId], [RestaurantInfo]) VALUES (@RestaurantUserId, @RestaurantInfo)"> <InsertParameters> <asp:Parameter Name="@UserId" Type="String" /> <asp:Parameter Name="RestaurantUserId" Type="String" /> <asp:Parameter Name="RestaurantInfo" Type="String" /> </InsertParameters> </asp:SqlDataSource> </div> </form> </body> </html> --- End of Code --- "Eliyahu Goldin" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... > 1.Add <asp:Parameter Name="@UserId" Type="String" /> to the > <InsertParameters> in the datasource and add UserId to the insert sql.. > > 2. Handle Inserting event for the datasource. In the event call > User.Identity.Name to get user name and then Membership.GetUser > (userName).ProviderUserKey to get user id. > > 3. In the same Inserting event, Locate the @UserId parameter in the insert > parameter collection as e.Command.Parameters["@UserId"]. Set it's value to > the user id obtained on step 2. > > -- > Eliyahu Goldin, > Software Developer > Microsoft MVP [ASP.NET] > http://msmvps.com/blogs/egoldin > http://usableasp.net > |
|
||
|
||||
|
Eliyahu Goldin
Guest
Posts: n/a
|
You already have a server script for FormView1_InsertButtonClick. Add there
an event handler for SqlDataSource1_Insering. Look up a bit msdn topics on SqlDataSource event. There is nothing special in handling them, it is just a regular programming task. You will face hundreds of them as you proceed with asp.net development. -- Eliyahu Goldin, Software Developer Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin http://usableasp.net "Jim" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... >I understood number 1, but not 2 and 3. I'm thinkng 2 and 3 have to do >with the script and that I have no idea past what I wrote. Here is what I >put in for all the code. Can you help with it from what you wrote. > Thanks. > . > -- Start of Code --- > <%@ Page Language="VB" %> > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > <script runat="server"> > Protected Sub FormView1_InsertButtonClick() > SqlDataSource1.Insert() > > End Sub > > </script> > > <html xmlns="http://www.w3.org/1999/xhtml"> > <head runat="server"> > <title>Untitled Page</title> > </head> > <body> > <form id="form1" runat="server"> > <div> > > <asp:FormView ID="FormView1" runat="server" > DataKeyNames="RestaurantID" > DataSourceID="SqlDataSource1" DefaultMode="Insert"> > <InsertItemTemplate> > RestaurantUserId: > <asp:TextBox ID="RestaurantUserIdTextBox" runat="server" > Text='<%# Bind("RestaurantUserId") %>' /> > <br /> > RestaurantInfo: > <asp:TextBox ID="RestaurantInfoTextBox" runat="server" > Text='<%# Bind("RestaurantInfo") %>' /> > <br /> > <asp:LinkButton ID="InsertButton" runat="server" > CausesValidation="True" > CommandName="Insert" Text="Insert" /> > <asp:LinkButton ID="InsertCancelButton" > runat="server" > CausesValidation="False" CommandName="Cancel" > Text="Cancel" /> > </InsertItemTemplate> > <ItemTemplate> > RestaurantID: > <asp:Label ID="RestaurantIDLabel" runat="server" > Text='<%# Eval("RestaurantID") %>' /> > <br /> > RestaurantUserId: > <asp:Label ID="RestaurantUserIdLabel" runat="server" > Text='<%# Bind("RestaurantUserId") %>' /> > <br /> > RestaurantInfo: > <asp:Label ID="RestaurantInfoLabel" runat="server" > Text='<%# Bind("RestaurantInfo") %>' /> > <br /> > <asp:LinkButton ID="EditButton" runat="server" > CausesValidation="False" > CommandName="Edit" Text="Edit" /> > <asp:LinkButton ID="DeleteButton" runat="server" > CausesValidation="False" > CommandName="Delete" Text="Delete" /> > <asp:LinkButton ID="NewButton" runat="server" > CausesValidation="False" > CommandName="New" Text="New" /> > </ItemTemplate> > </asp:FormView> > <asp:SqlDataSource ID="SqlDataSource1" runat="server" > ConnectionString="<%$ ConnectionStrings:ConnectionString %>" > InsertCommand="INSERT INTO [ZCRestaurant] ([RestaurantUserId], > [RestaurantInfo]) VALUES (@RestaurantUserId, @RestaurantInfo)"> > <InsertParameters> > <asp:Parameter Name="@UserId" Type="String" /> > <asp:Parameter Name="RestaurantUserId" Type="String" /> > <asp:Parameter Name="RestaurantInfo" Type="String" /> > </InsertParameters> > </asp:SqlDataSource> > > </div> > </form> > </body> > </html> > > --- End of Code --- > > "Eliyahu Goldin" <(E-Mail Removed)> wrote in > message news:(E-Mail Removed)... >> 1.Add <asp:Parameter Name="@UserId" Type="String" /> to the >> <InsertParameters> in the datasource and add UserId to the insert sql.. >> >> 2. Handle Inserting event for the datasource. In the event call >> User.Identity.Name to get user name and then Membership.GetUser >> (userName).ProviderUserKey to get user id. >> >> 3. In the same Inserting event, Locate the @UserId parameter in the >> insert parameter collection as e.Command.Parameters["@UserId"]. Set it's >> value to the user id obtained on step 2. >> >> -- >> Eliyahu Goldin, >> Software Developer >> Microsoft MVP [ASP.NET] >> http://msmvps.com/blogs/egoldin >> http://usableasp.net >> > > |
|
||
|
||||
|
Jim
Guest
Posts: n/a
|
Now I'm understanding what your refering to, but I'm looking for the event.
Where do I find the "FormView1_InsertButtonClick" code that is already there? "Eliyahu Goldin" <(E-Mail Removed)> wrote in message news:%(E-Mail Removed)... > You already have a server script for FormView1_InsertButtonClick. Add > there an event handler for SqlDataSource1_Insering. Look up a bit msdn > topics on SqlDataSource event. There is nothing special in handling them, > it is just a regular programming task. You will face hundreds of them as > you proceed with asp.net development. > > -- > Eliyahu Goldin, > Software Developer > Microsoft MVP [ASP.NET] > http://msmvps.com/blogs/egoldin > http://usableasp.net > > > "Jim" <(E-Mail Removed)> wrote in message > news:(E-Mail Removed)... >>I understood number 1, but not 2 and 3. I'm thinkng 2 and 3 have to do >>with the script and that I have no idea past what I wrote. Here is what I >>put in for all the code. Can you help with it from what you wrote. >> Thanks. >> . >> -- Start of Code --- >> <%@ Page Language="VB" %> >> >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> >> >> <script runat="server"> >> Protected Sub FormView1_InsertButtonClick() >> SqlDataSource1.Insert() >> >> End Sub >> >> </script> >> >> <html xmlns="http://www.w3.org/1999/xhtml"> >> <head runat="server"> >> <title>Untitled Page</title> >> </head> >> <body> >> <form id="form1" runat="server"> >> <div> >> >> <asp:FormView ID="FormView1" runat="server" >> DataKeyNames="RestaurantID" >> DataSourceID="SqlDataSource1" DefaultMode="Insert"> >> <InsertItemTemplate> >> RestaurantUserId: >> <asp:TextBox ID="RestaurantUserIdTextBox" runat="server" >> Text='<%# Bind("RestaurantUserId") %>' /> >> <br /> >> RestaurantInfo: >> <asp:TextBox ID="RestaurantInfoTextBox" runat="server" >> Text='<%# Bind("RestaurantInfo") %>' /> >> <br /> >> <asp:LinkButton ID="InsertButton" runat="server" >> CausesValidation="True" >> CommandName="Insert" Text="Insert" /> >> <asp:LinkButton ID="InsertCancelButton" >> runat="server" >> CausesValidation="False" CommandName="Cancel" >> Text="Cancel" /> >> </InsertItemTemplate> >> <ItemTemplate> >> RestaurantID: >> <asp:Label ID="RestaurantIDLabel" runat="server" >> Text='<%# Eval("RestaurantID") %>' /> >> <br /> >> RestaurantUserId: >> <asp:Label ID="RestaurantUserIdLabel" runat="server" >> Text='<%# Bind("RestaurantUserId") %>' /> >> <br /> >> RestaurantInfo: >> <asp:Label ID="RestaurantInfoLabel" runat="server" >> Text='<%# Bind("RestaurantInfo") %>' /> >> <br /> >> <asp:LinkButton ID="EditButton" runat="server" >> CausesValidation="False" >> CommandName="Edit" Text="Edit" /> >> <asp:LinkButton ID="DeleteButton" runat="server" >> CausesValidation="False" >> CommandName="Delete" Text="Delete" /> >> <asp:LinkButton ID="NewButton" runat="server" >> CausesValidation="False" >> CommandName="New" Text="New" /> >> </ItemTemplate> >> </asp:FormView> >> <asp:SqlDataSource ID="SqlDataSource1" runat="server" >> ConnectionString="<%$ ConnectionStrings:ConnectionString %>" >> InsertCommand="INSERT INTO [ZCRestaurant] ([RestaurantUserId], >> [RestaurantInfo]) VALUES (@RestaurantUserId, @RestaurantInfo)"> >> <InsertParameters> >> <asp:Parameter Name="@UserId" Type="String" /> >> <asp:Parameter Name="RestaurantUserId" Type="String" /> >> <asp:Parameter Name="RestaurantInfo" Type="String" /> >> </InsertParameters> >> </asp:SqlDataSource> >> >> </div> >> </form> >> </body> >> </html> >> >> --- End of Code --- >> >> "Eliyahu Goldin" <(E-Mail Removed)> wrote in >> message news:(E-Mail Removed)... >>> 1.Add <asp:Parameter Name="@UserId" Type="String" /> to the >>> <InsertParameters> in the datasource and add UserId to the insert sql.. >>> >>> 2. Handle Inserting event for the datasource. In the event call >>> User.Identity.Name to get user name and then Membership.GetUser >>> (userName).ProviderUserKey to get user id. >>> >>> 3. In the same Inserting event, Locate the @UserId parameter in the >>> insert parameter collection as e.Command.Parameters["@UserId"]. Set it's >>> value to the user id obtained on step 2. >>> >>> -- >>> Eliyahu Goldin, >>> Software Developer >>> Microsoft MVP [ASP.NET] >>> http://msmvps.com/blogs/egoldin >>> http://usableasp.net >>> >> >> > > |
|
||
|
||||
|
|
|
| |
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SessionID -> UserId Insert and View | Jim | Microsoft ASP .NET | 3 | 3rd Dec 2007 11:05 PM |
| Obtain and Insert UserID | =?Utf-8?B?YWpob21l?= | Microsoft Access Forms | 7 | 16th May 2007 07:58 PM |
| FormView Insert | AG | Microsoft ASP .NET | 6 | 14th Feb 2007 02:02 PM |
| Insert UserID after copy | =?Utf-8?B?ZGw=?= | Microsoft Access VBA Modules | 1 | 20th Mar 2006 04:46 PM |
| How use newest userid in auto INSERT (2.0) | VB Programmer | Microsoft ASP .NET | 2 | 13th Jan 2006 09:45 PM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |





