c# - 使用文本框在另一页上编辑 ListView 行

标签 c# asp.net

我必须创建一个页面,一个 aspx 页面,允许我修改与数据库关联的 ListView 行的数据,但我无法获取值。

我尝试做一个查询字符串

    protected void EditButton_Click(object sender, EventArgs e)
    {

      int id = Convert.ToInt32(((Button)sender).Attributes["ID_Persona"]);
      Response.Redirect("http://localhost:60082/pages/Edit.aspx" + "? 
      ID_Persona=" + id);
    }

并在我需要的页面上取值

        protected void Page_Load(object sender, EventArgs e)
        {

        TextBox1.Text = Request.QueryString.Get("ID_Persona").ToString();
        }

但我不知道如何在文本框中显示我要编辑的行。

这是重定向到编辑页面的按钮

    protected void EditButton_Click(object sender, EventArgs e)
    {
     int id = Convert.ToInt32(((Button)sender).Attributes["ID_Persona"]);
     Response.Redirect("http://localhost:60082/pages/Edit.aspx" + "? 
     ID_Persona=" + id);
    }

这是编辑页面

 public partial class Edit : System.Web.UI.Page
    { 
    string constr = 
    ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {

        TextBox1.Text = Request.QueryString.Get("ID_Persona").ToString();

    }

    protected void CustomerUpdate(object sender, EventArgs e)
    {
        CustomerUpdate();
    }
    private int Id
    {
        get
        {
            return !string.IsNullOrEmpty(Request.QueryString["ID"]) ? int.Parse(Request.QueryString["ID"]) : 0;
        }
    }
    private void CustomerUpdate()
    {
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand("UPDATE Persona SET Nome=@Nome, Cognome=@Cognome,Email=@Email,CodiceFiscale=@CodiceFiscale WHERE ID=@ID", con))
            {

                cmd.Parameters.AddWithValue("Nome", TextBox1.Text);
                cmd.Parameters.AddWithValue("Cognome", TextBox15.Text);
                cmd.Parameters.AddWithValue("Email", TextBox20.Text);
              cmd.Parameters.AddWithValue("CodiceFiscale",TextBox22.Text);
                cmd.Parameters.AddWithValue("ID", "");
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                Response.Redirect(Request.Url.AbsoluteUri, false);
                Response.Redirect("Dash.aspx");

            }
        }
    }
}

最佳答案

我认为您应该公开发送查询等信息的方法,但我不确定这是否有效。

关于c# - 使用文本框在另一页上编辑 ListView 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56577339/

相关文章:

asp.net - 将 ObjectDataSource 绑定(bind)到数据访问层中的现有方法

c# - 任何人都知道制作 MP3 Tag 应用程序需要什么?

c# - 我如何模拟 HttpRequestMessage,特别是 CreateResponse?

c# - MVC 4 强类型 View 不传递 Controller 模型

asp.net - 在 IIS URL 重写模块中自定义 HTTP header

asp.net - ASP.NET session 状态/NInject/OnePerRequest 行为的问题

c# - 更改 .net Framework dll 需要重新签名?

javascript - 如何复制 wwwroot 中的图片,或者如何引用它们?

.net - 事件不是从嵌套的 Accordion 控件中触发的

c# - 在与此域关联的配置文件中找不到部分 'caSTLe'