【问题标题】:Asp.Net leave comments abilityAsp.Net 留下评论能力
【发布时间】:2013-08-23 10:08:50
【问题描述】:

我有一个用户可以发表评论的页面。当用户单击提交存储在 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>

【问题讨论】:

  • 我想以更优雅的方式呈现评论。现在它就像一个经典的数据网格。我想像网页一样,您可以在页面底部发表评论。您必须开始实施,当您对该主题有更具体的问题时再回来。
  • 使用纯客户端代码jquery ajax和html来实现!!!

标签: c# jquery asp.net ajax


【解决方案1】:

我不知道你到底想做什么,但我认为你想用新样式在网格内的最后一个评论行...

您可以通过在网格行顶部添加最后一条评论并调用函数来做到这一点 onRowDataBound() ,并检查是否为第一行更改行样式

#更新

我看到您已经使用这些为每一行制作了不同的背景颜色

<AlternatingItemStyle BackColor="White" />
 <ItemStyle BackColor="#EFF3FB" />

现在关于字体,你可以创建模板字段来保存它的样式 像这样

<Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:Label runat="server" ID="lbl_Bind" Text='Eval(YOUR DATA HERE)' CssClass="CSS-CLASSS" />
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

【讨论】:

猜你喜欢
  • 2015-06-22
  • 2021-09-29
  • 1970-01-01
  • 1970-01-01
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多