获取Repeater中TextBox中的值

aspx页面

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
                                        <ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="updatename" OnClientClick="return confirm('确定要保存此修改吗?');"  CommandArgument='<%# Eval("XiangceId") %>'>改名</asp:LinkButton>

  <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Delete" CommandArgument='<%# Eval("XiangceId") %>' OnClientClick="return confirm( '你确定要删除这条记录? '); ">删除</asp:LinkButton>
 </ItemTemplate>
                                    </asp:Repeater>
cs页面
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

int id3 = Convert.ToInt32(e.CommandArgument);
        if (e.CommandName == "updatename")
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                TextBox textBox = (TextBox)e.Item.FindControl("tbName");
                //下面是自己的方法

                string strName = textBox.Text;
                string struid = uid.ToString();

                string strsql3 = "update Xiangce set Name='" + strName + "'  where XiangceId=" + id3;
                Response.Write(strsql3);
                int intNum = DAL.SqlServer2000.RunSql(strsql3);
                if (intNum != 0)
                {
                    ClassMessage.ShowAndRedirect(this.Page, "恭喜您,名称修改成功,!", "T_Pic_Sort.aspx");
                }
                else
                {
                    ClassMessage.Alert(this.Page, "对不起,名称修改失败!");
                }
            }           
        }

}

posted on 2009-08-31 15:14  周奇  阅读(889)  评论(0编辑  收藏  举报