日期:2014-05-18  浏览次数:20409 次

repeater怎么获取内部的html控件
前台
<asp:Repeater ID="Repeater1" runat="server">
  <ItemTemplate>
  <input id="Text1" name="Text1" type="text" value='<%#Eval("txt") %>' />
  <br />
  </ItemTemplate>
  <AlternatingItemTemplate>
  <input id="Text1" name="Text1" type="text" value='<%#Eval("txt") %>' />
  <br />
  </AlternatingItemTemplate>
  </asp:Repeater>


后台怎么获取text1的值?
string str = ((HtmlInputText)(Repeater1.Items[0].FindControl("Text1"))).Value;报错

------解决方案--------------------
点按钮post后,request.form["Text1"]
你这个都没有runat=“server”,后台肯定拿不到
------解决方案--------------------
name设成唯一的,并且可预测的,我就经常用 前缀+value的格式

<input id="Text1<%#Eval("txt") %>" name="Text1" type="text" value='<%#Eval("txt") %>' />

后台用request.form[“”]
------解决方案--------------------
探讨
前台
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<input id="Text1" name="Text1" type="text" value='<%#Eval("txt") %>' />
<br />
</ItemTemplat……

------解决方案--------------------
C# code

  protected void rpt_Role_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            ImageButton show = (ImageButton)e.Item.FindControl("imgBtnShow");
            ImageButton hidden = (ImageButton)e.Item.FindControl("imgBtnHidden");
            Panel pl_shDetail = (Panel)e.Item.FindControl("pl_ShowHiddenDetail");
            if (e.CommandName == "ShowDetail")
            {
                show.Visible = false;
                hidden.Visible = true;
                pl_shDetail.Visible = true;
                unFold(e);
            }
            if (e.CommandName == "HiddenDetail")
            {
                show.Visible = true;
                hidden.Visible = false;
                pl_shDetail.Visible = false;
            }
            if (e.CommandName == "edit")
            {
                GV_Detail.EditIndex = -1;
                string MemberID = e.CommandArgument.ToString();
                loadDetail(MemberID);
            }
        }

------解决方案--------------------
你用表单传值吧