J
Jim
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>
<asparameter Name="RestaurantUserId" Type="String" />
<asparameter Name="RestaurantInfo" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
---- End of page code ---
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>
<asparameter Name="RestaurantUserId" Type="String" />
<asparameter Name="RestaurantInfo" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
---- End of page code ---