English 中文(简体)
我如何在重复者内部再发布一次选择
原标题:How can I issue an additional select from within a repeater

我期待着一个能够表明我论坛中有多少答复专题的法典。 我有一个重复(REPEATER_1),以显示与标题和案文一样对每个专题的其他信息。 例如,为了获得所有权,我使用了:

<%# DataBinder.Eval(Container, "DataItem.title")%>

This works fine, but for counting replies, I need to access another table, and count all replies for this topic. I use the following SelectCommand:

"SELECT COUNT(ID) FROM [replies] WHERE parent= " & <%# DataBinder.Eval(Container, "DataItem.ID")%> & " ;"

But how do I execute this SelectCommand from within the Form (and within the repeater area) of the page using <%# XXXX.. %>

我知道有使用密码的替代品,但我正在采用这种方式;%# XXXX. %>

Also, what is it called when doing script inside a form using "<%# XXXX.. %>" ? It will make it easier for me to search on the web, as google or this website cannot search for "<%#"

最佳回答

I would do this in the ItemDataBound event of the Repeater.

www.un.org/Depts/DGACM/index_spanish.htm 我现在遵循你目前的做法,但你应回头来回答有关议题的提问。 您以这种方式重启数据库,多次重提数据库。

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    // !! use a parameterized query here to avoid SQL injection
    string query = String.Format("SELECT x FROM y WHERE z = {0}", DataBinder.Eval(e.Item.DataItem, "SomeColumn"));

    //execute your query to get reply count
    int replyCount = ExecuteQuery(query); // !! example

    Label lbl = e.Item.FindControl("ReplyCountLabel") as Label;
    if (lbl != null)
    {
        lbl.Text = replyCount.ToString()
    }
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签