嵌套的中继器和SqlDataSource的参数 [英] Nested Repeaters and SqlDataSource Parameters

查看:151
本文介绍了嵌套的中继器和SqlDataSource的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用嵌套的中继器来建一个表的原因,我不会在这里讨论,但是我希望做的是有两个数据源,一个是顶级中继器,将对应于行,一个用于第二个层次中继器,将行内返回细胞。

I am using nested repeaters to build a table for reasons I won't discuss here, but what I'm looking to do is have two datasources, one for the top level repeater that will correspond to the rows, and one for the second level repeater that will return cells within a row.

我不知道,但是,是,如果我能以某种方式指定,它被设置在从第一个数据源?

What I'm wondering, however, is if I can somehow specify a parameter in the nested repeater's datasource that is set a field in the results from the first datasource?

我可以将参数设置为数据的价值结合前pression?

Can I set a parameter to the value of a data binding expression?

我想这样做的原因是我有两个存储过程。当页面加载我有一个会话参数,我可以用它来运行第一个存储过程,但是,对于第二个存储过程,我需要从顶级直放站的每个实例的值与第二个存储过程的调用关联用不同的参数值。

The reason I want to do this is I have two stored procedures. When the page is loaded I have a session parameter I can use to run the first stored procedure, however, for the second stored procedure, I need to associate a value from each instance of the top level repeater with a call to the second stored procedure with a different parameter value.

推荐答案

我认为最好的办法是处理外直放站的ItemDataBound事件,查找内DataSource控件并设置SelectParameter吧。

I think the best way would be to handle the ItemDataBound event of the Outer Repeater, Find the inner DataSource control and set a SelectParameter for it.

    void MyOuterRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e) 
    {
    // Find the Inner DataSource control in this Row.
    SqlDataSource s = (SqlDataSource)e.Item.FindControl("InnerDataSource");

    // Set the SelectParameter for this DataSource control
    // by re-evaluating the field that is to be passed.
    s.SelectParameters["MyParam"].DefaultValue = DataBinder.Eval(e.Item.DataItem, "MyFieldValueToPass").ToString();
    }

有关使用DataList的一个例子,检查出的ASP.NET快速入门<一href=\"http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/data/NestedMasterDetailsList.src&file=NestedMasterDetailsList_cs.aspx&lang=C%23+Source\"相对=nofollow>这里

For an example using the DataList, check out the ASP.NET quickstarts here

P.S .:的请参见下面的托尼的答复一个重要修正上述presented片段。值得注意的是,这将是必不可少的检查当前的RepeaterItem的ItemType的。另外,它是一个很好的做法,总是空值检查每一个对象。

这篇关于嵌套的中继器和SqlDataSource的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆