前台
<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()好像根本就没有找到。
<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()好像根本就没有找到。
<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);
}
Repeater.Items 获取Repeater中RepeaterItem 对象的集合两个集合是不同的~~
for(int i =0;i<this.book.Controls.Count-1;i++)
{
tempd = tempd +"|"+this.book.Controls[i].controls.count;
}达出来看看?看看有没有count不是0的
有的话,看看里面是什么
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