我必须创建一个页面,一个 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/