2013-02-13 50 views
0

我有一些像rpA,rpB等id到'rpZ'的id中继器控件。我想要做的是我想在后面的代码中找到asp中继器,并相应地绑定一个数据源..到目前为止我编写的代码是在下面,其中'我'是一个整数,范围从65到90.并且'tb'是一个DataTable。如何找到asp转发器控件并将数据绑定到它

    string lblName = "lbl" + Convert.ToChar(i); 
        string repName = "rp" + Convert.ToChar(i); 
        FindControl(lblName).Visible = true; 
        FindControl(repName).Visible = true; 
        IDataBoundControl repID = FindControl(repName) as IDataBoundControl; 
        ITextControl lblID = FindControl(lblName) as ITextControl; 
        lblID.Text = (Convert.ToChar(i)).ToString(); 
        repID.DataSource = tb; 
        repID.DataBind(); 

,但我不能够进行数据绑定()。最后一行如果你给了一个错误“System.Web.UI.WebControls.IDataBoundControl不包含的DataBind的定义”

+1

什么错误? “tb”的价值是什么? – millimoose 2013-02-13 10:27:25

+0

请参阅我的编辑.. – Niar 2013-02-13 10:31:05

回答

3

知道是什么类型,然后做到这一点:

var repID = FindControl(repName) as Repeater; 
repID.DataSource = tb; 
repID.DataBind(); 

不点它转换为IDataBoundControl,因为这个界面没有办法DataBind()(更多信息here

+0

非常感谢man.this正是我所需要的..在6分钟后,我会将此标记为答案。 – Niar 2013-02-13 10:35:28

相关问题