我有一个用户可以发表评论的页面。当用户单击提交存储在 db 表中的此评论时。随着回发数据网格,我有 databind() 和我拥有的数据网格上显示的评论。我想以更优雅的方式呈现评论。现在它就像一个经典的数据网格。我想像网页一样,您可以在页面底部发表评论。我的代码:
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<strong>Post Comment</strong><br />
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
Name: <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("UserID") %>'></asp:TextBox><br />
Comments:<br />
<asp:TextBox ID="txtComments" runat="server" Text='<%# Bind("Comments") %>'
TextMode="MultiLine" Rows="4" Columns="50"></asp:TextBox><br />
<asp:HiddenField ID="hidTimeDate" runat="server" Value='<%# Bind("CommentDate") %>' />
<asp:Button ID="butSubmit" runat="server" CommandName="Insert" Text="Submit" /> </InsertItemTemplate>
</asp:FormView>
<asp:DataGrid ID="DataGrid1" runat="server"
Width="593px" CellPadding="4" ForeColor="#333333"
GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditItemStyle BackColor="#2461BF" />
<SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#EFF3FB" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
</asp:DataGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT [UserID], [CommentDate], [Comments] FROM [Comments]"
InsertCommand="INSERT Comments (UserID,Comments,CommentDate) VALUES (@UserID, @Comments, @CommentDate)"></asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>