我有一个详细信息视图,其中启用了“编辑/新建”。在“新”上,连同将进入数据库行的其他额外信息,我也在尝试发送当前登录的用户名。目前,它保持为空。
这是我的代码:
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="700px"
AutoGenerateRows="False" DataKeyNames="ID"
DataSourceID="AccessDataSource2" AllowPaging="True" CssClass="mdtlstblwithhlines">
<Fields>
<asp:TemplateField HeaderText="Rating" SortExpression="Rating">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Rating") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Rating") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Rating ID="Rating1" CurrentRating= '<%# Bind("Rating") %>'
runat="server" EmptyStarCssClass="EmptyStar"
FilledStarCssClass="FilledStar" StarCssClass="Star"
WaitingStarCssClass="WaitingStar" AutoPostBack="True" Enabled="True"
EnableTheming="True" ReadOnly="True">
</asp:Rating>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TheGood" HeaderText="TheGood"
SortExpression="TheGood" />
<asp:BoundField DataField="TheBad" HeaderText="TheBad"
SortExpression="TheBad" />
<asp:BoundField DataField="TheBottomLine" HeaderText="TheBottomLine"
SortExpression="TheBottomLine" />
<asp:BoundField DataField="DatePosted" HeaderText="DatePosted"
SortExpression="DatePosted" />
<asp:BoundField DataField="LastUpdate" HeaderText="LastUpdate"
SortExpression="LastUpdate" />
<asp:TemplateField HeaderText="UserName" SortExpression="UserName" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("UserName") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("UserName") %>' ></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("UserName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
</div>
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/ReviewSite.accdb"
SelectCommand="SELECT * FROM [ReviewsCam] WHERE ([ItemID] = ?)"
DeleteCommand="DELETE FROM [ReviewsCam] WHERE [ID] = ?"
InsertCommand="INSERT INTO [ReviewsCam] ([ItemID], [UserID], [UserName], [Rating], [TheGood], [TheBad], [TheBottomLine], [DatePosted], [LastUpdate]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
UpdateCommand="UPDATE [ReviewsCam] SET [ItemID] = ?, [UserID] = ?, [UserName] = ?, [Rating] = ?, [TheGood] = ?, [TheBad] = ?, [TheBottomLine] = ?, [DatePosted] = ?, [LastUpdate] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ItemID" Type="Int32" />
<asp:Parameter Name="UserID" Type="String" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="Rating" Type="Int32" />
<asp:Parameter Name="TheGood" Type="String" />
<asp:Parameter Name="TheBad" Type="String" />
<asp:Parameter Name="TheBottomLine" Type="String" />
<asp:Parameter Name="DatePosted" Type="DateTime" />
<asp:Parameter Name="LastUpdate" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="ItemID2" QueryStringField="ID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ItemID" Type="Int32" />
<asp:Parameter Name="UserID" Type="String" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="Rating" Type="Int32" />
<asp:Parameter Name="TheGood" Type="String" />
<asp:Parameter Name="TheBad" Type="String" />
<asp:Parameter Name="TheBottomLine" Type="String" />
<asp:Parameter Name="DatePosted" Type="DateTime" />
<asp:Parameter Name="LastUpdate" Type="DateTime" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:AccessDataSource>