将wpf数据网格转换为asp网格视图

本文关键字:网格 asp 视图 转换 数据 数据网 wpf | 更新日期: 2023-09-27 18:00:16

此c#代码在wpf框架中运行良好。现在我需要asp.net中的这段代码。我使用的是GridView而不是DataGrid。我需要做什么改变?

这是我的c#代码:

DataRowView SelectedRowValue = (DataRowView)dataGrid1.SelectedValue;
byte[] ImageBytes = (byte[])SelectedRowValue.Row.ItemArray[1];
MySqlCommand cmd2 = new MySqlCommand("INSERT INTO Images (Image) VALUES (@ImageSource)", con);
cmd2.Parameters.Add("@ImageSource", MySqlDbType.Blob, ImageBytes.Length).Value = ImageBytes;
cmd2.ExecuteNonQuery();

将wpf数据网格转换为asp网格视图

您可以使用c#使用Grid_RowUpdating事件 protected void oGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; Label lblID = (Label)row.FindControl("Label1"); TextBox txtImage = (TextBox)row.Cells[0].Controls[0]; //........ Then Update Command for MySQl which You are using// MySqlCommand oMySqlCommand = connection.CreateCommand(); oMySqlCommand.CommandText = ""update detail set Image='"+txtImage.Text+"'where id='"+userid+"'"; connection.Open(); command.ExecuteNonQuery();//.......etc// GridView1.EditIndex = -1; }