将wpf datagrid转换为asp gridview

时间:2016-08-05 09:18:54

标签: c# gridview datagrid

这个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();

1 个答案:

答案 0 :(得分:0)

您可以使用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; }