前台
<asp:Repeater ID="book" Runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center" width="40" bgColor="#ffffff" height="15">技能</td>
<td bgColor="#ffffff" height="15"><%#DataBinder.Eval(Container,"DataItem.d1")%></td>
<TD width="53" bgColor="#ffffff" height="15">
<select id="S<%#DataBinder.Eval(Container,"DataItem.id")%>" runat="server" style="WIDTH: 100%; CLIP: rect(1px 38px 19px 1px); HEIGHT: 100%" name="select">
<OPTION value="" selected></OPTION>
<OPTION value="√">√</OPTION>
<OPTION value="○">○</OPTION>
<OPTION value="×">×</OPTION>
</select></select>
</TD>
</tr>
</ItemTemplate>
</asp:Repeater>后台提交表格的时候想要得到select的值传到数据库中
        HtmlSelect tempselect;
                tempselect  = (HtmlSelect)this.book.FindControl(select的id值);
                sql="update table set d2='"+tempselect.Value+"' where id='"+id+"'";
                提示错误:未将对象引用设置到对象的实例         tempselect.Value好像没得到值查看生成的页面代码:发现所有的select的runat=server消失了。我把select换成dropdownlist ,结果页面显示的不是下拉框,而是直接把所有的select的每个值都写成一行,显示出来了。但这次的runat=server却没有丢失。我又在提交表格中写入:
string tempd ="";
for(int i =0;i<this.book.Controls.Count;i++)
{
tempd = tempd +"|"+this.book.Controls[i].ID.ToString();
}
this.Response.Write(this.book.Controls.Count+"|"+tempd);
结果应该是9个结果,可是this.book,Controls.Count = 10
而且this.book.Controls[i].ID.ToString()好像根本就没有找到。

解决方案 »

  1.   

    for(int i =0;i<this.book.Controls.Count;i++)把其中的i=0改成i=1
      

  2.   

    首先,你并没有必要给Select控件一个动态的id,直接这样就可以了:
    <select id='mySelect' runat="server" 提交:
    for(int i=0;i<this.book.Items.Count;i++)
    {
    HtmlSelect s = (HtmlSelect)this.book.Items[i].FindControl("mySelect");
    Response.Write(s.Value);
    }
      

  3.   

    Repeater.Controls  获取 Repeater 子控件
    Repeater.Items  获取Repeater中RepeaterItem 对象的集合两个集合是不同的~~
      

  4.   

    string tempd ="";
    for(int i =0;i<this.book.Controls.Count-1;i++)
    {
    tempd = tempd +"|"+this.book.Controls[i].controls.count;
    }达出来看看?看看有没有count不是0的
    有的话,看看里面是什么
      

  5.   


    string tempd ="";
    for(int i =0;i<this.book.Controls.Count-1;i++)
    {
    tempd = tempd +"|"+this.book.Controls[i].controls.count;
    }达出来看看?看看有没有count不是0的
    有的话,看看里面是什么结果是:
    |1|3|3|3|3|3|3|3|3