Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 2.34 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Run script in Repeater and display result
  2. <asp:Repeater ID="topicView" runat="server">
  3.     <HeaderTemplate>
  4.         <table width="925px" cellpadding="0" cellspacing="0">
  5.             <tr>
  6.                 <td style="text-align:left;" class="topic-header-home"><strong>Topic Title</strong></td>
  7.                 <td width="10%" class="topic-header-home"><strong>Posts</strong></td>
  8.                 <td width="20%" class="topic-header-home"><strong>Started By</strong></td>
  9.             </tr>
  10.     </HeaderTemplate>
  11.     <ItemTemplate>        
  12.         <tr>
  13.             <td style="text-align:left;" class="topic-cont-home">
  14.                 <p><a href='view.aspx?topicID=<%#DataBinder.Eval(Container.DataItem, "TopicID")%>'><strong><%#DataBinder.Eval(Container.DataItem, "TopicName")%></strong></a></p>
  15.             </td>
  16.             <td class="topic-cont-home">
  17.                 <script type="text/C#">
  18.                     // Define the select statement.
  19.                     // All information is needed
  20.                     string selectPostCount = "select count(*) from Posts WHERE TopicID=@topicID";
  21.                     // Define the ADO.NET Objects
  22.                     using (SqlConnection con = new SqlConnection(connectionString))
  23.                     {
  24.                         SqlCommand pccmd = new SqlCommand(selectPostCount, con);
  25.                         pccmd.Parameters.AddWithValue("@topicID", <%#DataBinder.Eval(Container.DataItem, "TopicID")%>);
  26.                         con.Open();
  27.                         int numrows = (int)pccmd.ExecuteScalar();
  28.                         string posts = numrows.ToString();
  29.                         con.Close();
  30.                         posts.InnerHTML = posts;
  31.                     }
  32.                 </script>
  33.                 <p id="posts" runat="server"></p>
  34.             </td>
  35.             <td class="topic-cont-home">
  36.                 <p><strong><%#DataBinder.Eval(Container.DataItem, "Username")%></strong></p>
  37.             </td>
  38.         </tr>
  39.     </ItemTemplate>
  40.     <FooterTemplate>
  41.         </table>
  42.     </FooterTemplate>
  43. </asp:Repeater>
  44.        
  45. <asp:Repeater runat="server" ID="repeater">
  46.     <ItemTemplate>
  47.  
  48.         <p id="posts" runat="server"><%#GetNumberOfRows((int)DataBinder.Eval(Container.DataItem, "TopicID"))%></p>
  49.     </ItemTemplate>
  50.    </asp:Repeater>
  51.  
  52. protected int GetNumberOfRows(int topicId)
  53.     {
  54.        //Run query and return result
  55.  
  56.     }