为何REPEATER取不到TEXTBOX中的值。

JGH8041 2010-05-24 03:25:43

protected void OverOrderRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{


if (e.CommandName == "Mod")
{
server = new Server();
long longIp = long.Parse(e.CommandArgument.ToString());
server.Longip = longIp;
server.Beizhu = ((TextBox)this.OverOrderRepeater.Items[e.Item.ItemIndex].FindControl("beizhuTextBox")).Text.Trim();

}
BindOverOrderRepeater();
}
...全文
203 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
aluogang 2010-05-24
  • 打赏
  • 举报
回复
我显示的一个效果而已,鼠标移到Repeater1那一行数据加个背景颜色,没别的
JGH8041 2010-05-24
  • 打赏
  • 举报
回复
onitemdatabound="Repeater1_ItemDataBound"

是什么?有关系吗?
  • 打赏
  • 举报
回复
请确定textbox的 runnt="sever"是否还存在
aluogang 2010-05-24
  • 打赏
  • 举报
回复
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<tr class="RowStyle">
<td><%#Eval("username") %></td>
<td><asp:Textbox ID="txtAge" runnt="sever" Text='<%#Eval("age") %>'</td>
<td><asp:LinkButton ID="lbtnUpdate" runat="server" CommandArgument=' <%# Container.DataItemIndex %>' CommandName="Update">修改</asp:LinkButton></td>
</tr>
</ItemTemplate>
</asp:Repeater>
修改年龄
JGH8041 2010-05-24
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 aluogang 的回复:]
string beizhuTextBox= null;
beizhuTextBox= ((TextBox)OverOrderRepeater.Items[Convert.ToInt32(e.CommandArgument.ToString())].FindControl("beizhuTextBox")).Text.Trim();
mod的CommandArgument=' <%# Con……
[/Quote]

你能把前台信息给我吗?
aluogang 2010-05-24
  • 打赏
  • 举报
回复
string beizhuTextBox= null;
beizhuTextBox= ((TextBox)OverOrderRepeater.Items[Convert.ToInt32(e.CommandArgument.ToString())].FindControl("beizhuTextBox")).Text.Trim();
mod的CommandArgument=' <%# Container.DataItemIndex %>'

都改了你取不到?我刚试了怎么能取到.......
JGH8041 2010-05-24
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 zx75991 的回复:]
行号索引死否取值正确。
这个索引对了才能用findcontrol方法找到TextBox,然后取得值。
建议楼主把代码稍微改下执行。
比如原来: string item1 = ((TextBox)Repeater1.Items[index].FindControl("TextBox1")).Text;
改为:
TextBox temp=Repeater1.Items[index].Find……
[/Quote]

行号肯定没问题,总共就两行,我分别都改了值。
JGH8041 2010-05-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 liyoubaidu 的回复:]
我想了下,因为你不让程序取到textbox的值。
[/Quote]

???
天下在我心 2010-05-24
  • 打赏
  • 举报
回复
行号索引死否取值正确。
这个索引对了才能用findcontrol方法找到TextBox,然后取得值。
建议楼主把代码稍微改下执行。
比如原来: string item1 = ((TextBox)Repeater1.Items[index].FindControl("TextBox1")).Text;
改为:
TextBox temp=Repeater1.Items[index].FindControl("TextBox1"))as TextBox;
string item1=temp.Text.Trim();
这样,加上调试,了解哪一步取值不正确,从而逐步解决问题.
liyoubaidu 2010-05-24
  • 打赏
  • 举报
回复
我想了下,因为你不让程序取到textbox的值。
JGH8041 2010-05-24
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 koukoujiayi 的回复:]
如果你的按钮是Button,则:

C# code
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Mod")
{
Button myL = (Butto……
[/Quote]

不行啊,还是一样取不到值。
koukoujiayi 2010-05-24
  • 打赏
  • 举报
回复
如果你的按钮是Button,则:
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Mod")
{
Button myL = (Button)e.CommandSource;
int index = ((RepeaterItem)(myL.NamingContainer)).ItemIndex;//获得行号
string item1 = ((TextBox)Repeater1.Items[index].FindControl("TextBox1")).Text;
Response.Write(item1);
}
}

如果按钮是LinkButton则:
Button myL = (Button)e.CommandSource;
改为
LinkButton myL = (LinkButton)e.CommandSource;

JGH8041 2010-05-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 aluogang 的回复:]
你那个mod的CommandArgument=' <%# Container.DataItemIndex %>'用这个试试
[/Quote]

这个不是关键,自己可以设定。
细嗅蔷薇 2010-05-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 aluogang 的回复:]
你那个mod的CommandArgument=' <%# Container.DataItemIndex %>'用这个试试
[/Quote]
加上看行不行
aluogang 2010-05-24
  • 打赏
  • 举报
回复
你那个mod的CommandArgument=' <%# Container.DataItemIndex %>'用这个试试
JGH8041 2010-05-24
  • 打赏
  • 举报
回复
LABEL可以取到,TEXTBOX确不能这是为什么?
JGH8041 2010-05-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 aluogang 的回复:]
string beizhuTextBox= null;
beizhuTextBox= ((TextBox)OverOrderRepeater.Items[Convert.ToInt32(e.CommandArgument.ToString())].FindControl("beizhuTextBox")).Text.Trim();
[/Quote]

兄弟别耍我啦,“Convert.ToInt32(e.CommandArgument.ToString())”这个不是列表项序号。
aluogang 2010-05-24
  • 打赏
  • 举报
回复
string beizhuTextBox= null;
beizhuTextBox= ((TextBox)OverOrderRepeater.Items[Convert.ToInt32(e.CommandArgument.ToString())].FindControl("beizhuTextBox")).Text.Trim();

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧