无法获取repeater中的值
aspx中
<ItemTemplate>
<tr bgcolor= "#ffcc66 ">
<td> <%# DataBinder.Eval(Container, "DataItem.CustNo ") %>
<p> <asp:TextBox ID= "txt " Runat=server> </asp:TextBox>
<asp:RadioButton ID= "Radiobutton1 " Runat= "server " GroupName= "ff "> </asp:RadioButton> <%# DataBinder.Eval(Container, "DataItem.company ") %>
<p> <asp:RadioButton ID= "Radiobutton2 " Runat= "server " GroupName= "ff "> </asp:RadioButton> <%# DataBinder.Eval(Container, "DataItem.City ") %>
</td>
</tr>
</ItemTemplate>
cs中button的click事件
StringBuilder builder1=new StringBuilder();
foreach(RepeaterItem item1 in Repeater1.Items)
{
RadioButton ck=(RadioButton)item1.FindControl( "Radiobutton1 ");
if (ck.Checked)builder1.Append( "A ");
else
builder1.Append( "B ");
builder1.Append(((TextBox)item1.FindControl( "txt ")).Text);
}
Response.Write(builder1.ToString());
问题:为什么ck.Checked永远都为false,而且textbox里的值也取不到。
实在找不出错在哪里,请大侠帮看看!
可以通过(RadioButton)item1.FindControl( "Radiobutton1 ")).Checked=true;正常赋值,但就是取不到
[解决办法]
你在Page_Load加载的时候是否进行了IsPostBack的判断?
[解决办法]
IsPostBack
为什么最近那么多人犯此类错误, 回家好好做功课去, 呵呵.
[解决办法]
!IsPostBack