
Untitled
By: a guest on
Jul 24th, 2012 | syntax:
None | size: 2.34 KB | hits: 12 | expires: Never
Run script in Repeater and display result
<asp:Repeater ID="topicView" runat="server">
<HeaderTemplate>
<table width="925px" cellpadding="0" cellspacing="0">
<tr>
<td style="text-align:left;" class="topic-header-home"><strong>Topic Title</strong></td>
<td width="10%" class="topic-header-home"><strong>Posts</strong></td>
<td width="20%" class="topic-header-home"><strong>Started By</strong></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="text-align:left;" class="topic-cont-home">
<p><a href='view.aspx?topicID=<%#DataBinder.Eval(Container.DataItem, "TopicID")%>'><strong><%#DataBinder.Eval(Container.DataItem, "TopicName")%></strong></a></p>
</td>
<td class="topic-cont-home">
<script type="text/C#">
// Define the select statement.
// All information is needed
string selectPostCount = "select count(*) from Posts WHERE TopicID=@topicID";
// Define the ADO.NET Objects
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand pccmd = new SqlCommand(selectPostCount, con);
pccmd.Parameters.AddWithValue("@topicID", <%#DataBinder.Eval(Container.DataItem, "TopicID")%>);
con.Open();
int numrows = (int)pccmd.ExecuteScalar();
string posts = numrows.ToString();
con.Close();
posts.InnerHTML = posts;
}
</script>
<p id="posts" runat="server"></p>
</td>
<td class="topic-cont-home">
<p><strong><%#DataBinder.Eval(Container.DataItem, "Username")%></strong></p>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater runat="server" ID="repeater">
<ItemTemplate>
<p id="posts" runat="server"><%#GetNumberOfRows((int)DataBinder.Eval(Container.DataItem, "TopicID"))%></p>
</ItemTemplate>
</asp:Repeater>
protected int GetNumberOfRows(int topicId)
{
//Run query and return result
}