如何访问Repeater FooterTemplate TextBox?

时间:2011-09-22 22:07:23

标签: asp.net

  • 我要做的是从TextBox1访问值以在屏幕上显示。
  • 我试图从Page_Load()和OnItemDataBound访问它们,但它们都失败了。
  • 看起来代码能够访问控件,但它不返回任何内容。

    protected void Page_Load(object sender,EventArgs e)     {

        Literal Literal1 = (Literal)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("Literal1");
        Response.Write(Literal1.Text);
        //this techique is not working for the line below
        TextBox TextBox1 = (TextBox)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("TextBox1");
        Response.Write(TextBox1.Text);
    
    }
    public void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        //this techique is not working
        if (e.Item.ItemType == ListItemType.Footer)
        {
            TextBox TextBox1 = (TextBox)e.Item.FindControl("TextBox1");
            Response.Write(TextBox1.Text);
        }
    }
    

2 个答案:

答案 0 :(得分:1)

我不确定你的意思是“他们都失败了”但是如果Textbox的Text属性为空,我可能是因为你在每个帖子上重新绑定你的转发器。尝试使用!IsPostBack条件包装转发器.DataBind()。

答案 1 :(得分:0)

我必须通过传递html Textbox问题来使用“Literal”作为替代解决方案。我不喜欢这个解决方案,但我想我必须使用它。