Repeater中找到控件&Repeater中的Button处理
Repeater中找到控件
分析:循环所有Repeater中的Item即可
在Repeater1.DataBind()后加入
Repeater中的Button处理
前台:
分析:循环所有Repeater中的Item即可
在Repeater1.DataBind()后加入
int count = Repeater1.Items.Count;
for (int i = 0; i < count; i++)
{
TextBox cjry = Repeater1.Items[i].FindControl("txt_Cjry") as TextBox;
}
for (int i = 0; i < count; i++)
{
TextBox cjry = Repeater1.Items[i].FindControl("txt_Cjry") as TextBox;
}
Repeater中的Button处理
前台:
<asp:Button ID="btn_Edit" runat="server" Text="修 改" CommandName="edit" CommandArgument='<%#Bind("id") %>' />
后台: protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "edit")
{
RepeaterItem ri = e.Item;
TextBox ycjrs_child = ri.FindControl("txt_Ycjrs") as TextBox;
TextBox scjrs_child = ri.FindControl("txt_Scjrs") as TextBox;
TextBox cjry_child = ri.FindControl("txt_Cjry") as TextBox;
TextBox qxr_child = ri.FindControl("txt_Qxr") as TextBox;
TextBox ldqz_child = ri.FindControl("txt_Ldqz") as TextBox;
TextBox zcr_child = ri.FindControl("txt_Zcr") as TextBox;
TextBox jlr_child = ri.FindControl("txt_Jlr") as TextBox;
TextBox hdnr_child = ri.FindControl("txt_Hdnr") as TextBox;
TextBox fyjl_child = ri.FindControl("txt_Fyjl") as TextBox;
TextBox fxgz_child = ri.FindControl("txt_Fxgz") as TextBox;
TextBox bkqk_child = ri.FindControl("txt_Bkqk") as TextBox;
int id_user = Convert.ToInt32(Session["id"].ToString());
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(strConn))
{
conn.Open();
string strCmd = "update [hdjl] set [ycjrs]=@ycjrs,[scjrs]=@scjrs,[cjry]=@cjry,[qxr]=@qxr,[ldqz]=@ldqz,[zcr]=@zcr,[jlr]=@jlr,[hdnr]=@hdnr,[grfyjl]=@grfyjl,[fxgz]=@fxgz,[bkqk]=@bkqk,[id_user]=@id_user where [id]=@id";
using (SqlCommand cmd = new SqlCommand(strCmd, conn))
{
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@ycjrs", ycjrs_child.Text.ToString());
cmd.Parameters.AddWithValue("@scjrs", scjrs_child.Text.ToString());
cmd.Parameters.AddWithValue("@cjry", cjry_child.Text.ToString());
cmd.Parameters.AddWithValue("@qxr", qxr_child.Text.ToString());
cmd.Parameters.AddWithValue("@ldqz", ldqz_child.Text.ToString());
cmd.Parameters.AddWithValue("@zcr", zcr_child.Text.ToString());
cmd.Parameters.AddWithValue("@jlr", jlr_child.Text.ToString());
cmd.Parameters.AddWithValue("@hdnr", hdnr_child.Text.ToString());
cmd.Parameters.AddWithValue("@grfyjl", fyjl_child.Text.ToString());
cmd.Parameters.AddWithValue("@fxgz", fxgz_child.Text.ToString());
cmd.Parameters.AddWithValue("@bkqk", bkqk_child.Text.ToString());
cmd.Parameters.AddWithValue("@id_user", id_user);
cmd.Parameters.AddWithValue("@id", e.CommandArgument);
if (cmd.ExecuteNonQuery() > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功');location.href='hdjl_query.aspx'</script>");
}
}
}
}
}
{
if (e.CommandName == "edit")
{
RepeaterItem ri = e.Item;
TextBox ycjrs_child = ri.FindControl("txt_Ycjrs") as TextBox;
TextBox scjrs_child = ri.FindControl("txt_Scjrs") as TextBox;
TextBox cjry_child = ri.FindControl("txt_Cjry") as TextBox;
TextBox qxr_child = ri.FindControl("txt_Qxr") as TextBox;
TextBox ldqz_child = ri.FindControl("txt_Ldqz") as TextBox;
TextBox zcr_child = ri.FindControl("txt_Zcr") as TextBox;
TextBox jlr_child = ri.FindControl("txt_Jlr") as TextBox;
TextBox hdnr_child = ri.FindControl("txt_Hdnr") as TextBox;
TextBox fyjl_child = ri.FindControl("txt_Fyjl") as TextBox;
TextBox fxgz_child = ri.FindControl("txt_Fxgz") as TextBox;
TextBox bkqk_child = ri.FindControl("txt_Bkqk") as TextBox;
int id_user = Convert.ToInt32(Session["id"].ToString());
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(strConn))
{
conn.Open();
string strCmd = "update [hdjl] set [ycjrs]=@ycjrs,[scjrs]=@scjrs,[cjry]=@cjry,[qxr]=@qxr,[ldqz]=@ldqz,[zcr]=@zcr,[jlr]=@jlr,[hdnr]=@hdnr,[grfyjl]=@grfyjl,[fxgz]=@fxgz,[bkqk]=@bkqk,[id_user]=@id_user where [id]=@id";
using (SqlCommand cmd = new SqlCommand(strCmd, conn))
{
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@ycjrs", ycjrs_child.Text.ToString());
cmd.Parameters.AddWithValue("@scjrs", scjrs_child.Text.ToString());
cmd.Parameters.AddWithValue("@cjry", cjry_child.Text.ToString());
cmd.Parameters.AddWithValue("@qxr", qxr_child.Text.ToString());
cmd.Parameters.AddWithValue("@ldqz", ldqz_child.Text.ToString());
cmd.Parameters.AddWithValue("@zcr", zcr_child.Text.ToString());
cmd.Parameters.AddWithValue("@jlr", jlr_child.Text.ToString());
cmd.Parameters.AddWithValue("@hdnr", hdnr_child.Text.ToString());
cmd.Parameters.AddWithValue("@grfyjl", fyjl_child.Text.ToString());
cmd.Parameters.AddWithValue("@fxgz", fxgz_child.Text.ToString());
cmd.Parameters.AddWithValue("@bkqk", bkqk_child.Text.ToString());
cmd.Parameters.AddWithValue("@id_user", id_user);
cmd.Parameters.AddWithValue("@id", e.CommandArgument);
if (cmd.ExecuteNonQuery() > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功');location.href='hdjl_query.aspx'</script>");
}
}
}
}
}

浙公网安备 33010602011771号