google了一个方法 TextBox t = (TextBox)sender;
 RepeaterItem ri = (RepeaterItem)t.NamingContainer;
 str = ((HiddenField)ri.FindControl("answer_tbx")).Value; 
提示错误:无法将类型为“System.Web.UI.WebControls.TextBox”的对象强制转换为类型“System.Web.UI.WebControls.HiddenField”请问还有其他方法吗

解决方案 »

  1.   


    foreach(repeaterItem item in rpt)
    {
        TextBox t=(TextBox)item.FindControl("answer_tbx");
    }TextBox t = (TextBox)sender;//你这个肯定不行啦。
      

  2.   

    TextBox t = (TextBox)sender错误,要理解是代表Reperter不是TextBox
      

  3.   

      for (int i = 0; i < rpDynamicNewsManage.Items.Count; i++)
                {
        
    TextBox tb=(TextBox))rpDynamicNewsManage.Items[i].FindControl("single_Chk").text;
                 }
    这样试试
      

  4.   

    这是在外面使用。如果在ItemDataBound 则直接
    TextBox tb=(TextBox))e.Items.FindControl("single_Chk");
      

  5.   

    类型不对
    ((TextBox)ri.FindControl("answer_tbx")).Value; 
      

  6.   

    你要找的控件是textbox对吧?而你这answer_tbx是一个隐藏控件的名称呢还是textbox的名称呢?
    要是找textbox的话:
    str = ((TextBox)ri.FindControl("answer_tbx")).Text;
    要不是:
    str = ((HiddenField)ri.FindControl("隐藏控件名称")).Value;
      

  7.   


    或者 (ri.FindControl("answer_tbx") as TextBox).Value;
      

  8.   

    我们平常用的方案:都是用js获取值。
    方案:前台放上一个hiddenId 作为服务器控件。
    然后将值保存到hiddenId中后台获取就OK。
    所以说lz得先将js搞懂,json,数组等搞懂