如何在特定帖子上插入特定评论?(如 Facebook)我在 sql 中有两个表
- wall=>wallid,用户名,帖子
- 发表评论=>墙ID,评论,评论ID
当我手动插入墙 ID 时,它工作正常,但我希望墙 ID 应该自动生成到我输入评论的帖子中。
在设计部分
<div style="text-align: center">
<asp:TextBox ID="TextBox1" runat="server" Height="61px" TextMode="MultiLine" Width="271px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Height="37px" Text="Submit" Width="91px" OnClick="Button1_Click" />
</div>
<div>
<br />
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<div style="border: solid 2px brown; width: 400px; margin-bottom: 20px">
<span style="">Id:
<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("wallId") %>' />
<br />
post:
<asp:Label ID="postLabel" runat="server" Text='<%# Eval("post") %>' />
<br />
username:
<asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' />
<br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
<asp:ListView ID="ListView2" runat="server" DataSourceID="SqlDataSource2" DataKeyNames="commentID" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<span style="">commentID:<asp:Label Text='<%# Eval("commentID") %>' runat="server" ID="commentIDLabel" />
<br />
wallID:<asp:Label Text='<%# Eval("wallID") %>' runat="server" ID="wallIDLabel" />
<br />
comment:<asp:Label Text='<%# Eval("comment") %>' runat="server" ID="commentLabel" />
<br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</AlternatingItemTemplate>
<EditItemTemplate>
<span style="">commentID:<asp:Label Text='<%# Eval("commentID") %>' runat="server" ID="commentIDLabel1" />
<br />
wallID:<asp:TextBox Text='<%# Bind("wallID") %>' runat="server" ID="wallIDTextBox" />
<br />
comment:<asp:TextBox Text='<%# Bind("comment") %>' runat="server" ID="commentTextBox" />
<br />
<asp:Button runat="server" CommandName="Update" Text="Update" ID="UpdateButton" /><asp:Button runat="server" CommandName="Cancel" Text="Cancel" ID="CancelButton" /><br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</EditItemTemplate>
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<InsertItemTemplate>
<span style="">wallID:<asp:TextBox Text='<%# Bind("wallID") %>' runat="server" ID="wallIDTextBox" />
<br />
comment:<asp:TextBox Text='<%# Bind("comment") %>' runat="server" ID="commentTextBox" />
<br />
<asp:Button runat="server" CommandName="Insert" Text="Insert" ID="InsertButton" /><asp:Button runat="server" CommandName="Cancel" Text="Clear" ID="CancelButton" /><br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</InsertItemTemplate>
<ItemTemplate>
<span style="">commentID:<asp:Label Text='<%# Eval("commentID") %>' runat="server" ID="commentIDLabel" />
<br />
wallID:<asp:Label Text='<%# Eval("wallID") %>' runat="server" ID="wallIDLabel" />
<br />
comment:<asp:Label Text='<%# Eval("comment") %>' runat="server" ID="commentLabel" />
<br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</ItemTemplate>
<LayoutTemplate>
<div runat="server" id="itemPlaceholderContainer" style=""><span runat="server" id="itemPlaceholder" /></div>
<div style="">
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<span style="">commentID:<asp:Label Text='<%# Eval("commentID") %>' runat="server" ID="commentIDLabel" />
<br />
wallID:<asp:Label Text='<%# Eval("wallID") %>' runat="server" ID="wallIDLabel" />
<br />
comment:<asp:Label Text='<%# Eval("comment") %>' runat="server" ID="commentLabel" />
<br />
<br />
</span>
<br />
<hr style="height: 3px; background-color: blue" />
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource runat="server" ID="SqlDataSource2" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT * FROM [postcomment]" ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM [postcomment] WHERE [commentID] = @original_commentID AND [wallID] = @original_wallID AND (([comment] = @original_comment) OR ([comment] IS NULL AND @original_comment IS NULL))" InsertCommand="INSERT INTO [postcomment] ([wallID], [comment]) VALUES (@wallID, @comment)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [postcomment] SET [wallID] = @wallID, [comment] = @comment WHERE [commentID] = @original_commentID AND [wallID] = @original_wallID AND (([comment] = @original_comment) OR ([comment] IS NULL AND @original_comment IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_commentID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="original_wallID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="original_comment" Type="String"></asp:Parameter>
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="wallID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="comment" Type="String"></asp:Parameter>
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="wallID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="comment" Type="String"></asp:Parameter>
<asp:Parameter Name="original_commentID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="original_wallID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="original_comment" Type="String"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT * FROM [wall]"></asp:SqlDataSource>
</div>