Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/09/2008, 10:16
alesin
 
Fecha de Ingreso: julio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 0
Problema Update DetailsView

Buenas.
Tengo un problema con un DetailsView que no consigo que me actulice el valor de un campo. En modo edicion genero un TextBox para introducir los datos, pero desde el evento Update no consigo encontrar el control TextBox para pasar los datos a la consulta Update.

La consulta Update funciona pues probando con un texto en el parametro se actualiza, asi que el problema pararece estar en que no encuentro el control.
¿Saben que me puede pasar?

Este es el codigo que tengo:

**************** ASP.NET *******************
<asp:DetailsView ID="solucionDetalle" runat=server AutoGenerateRows="False" OnModeChanging="solucionDetalle_ModeChanging" OnItemUpdating="solucionDetalle_ItemUpdating" >
<Fields>
<asp:BoundField DataField="Fecha" HeaderText="Fecha" ReadOnly="True" />
<asp:BoundField DataField="UserName" HeaderText="Consultor" ReadOnly="True" />
<asp:TemplateField HeaderText="Solucion">
<EditItemTemplate>
<asp:TextBox ID="solucionTextBox" runat="server" Text='<%# Bind("Solucion") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="solucionTextBox1" runat="server" Text='<%# Bind("Solucion") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Solucion") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
<HeaderTemplate>
Solucion
</HeaderTemplate>
</asp:DetailsView>

************************* Code C# *********************

protected void solucionDetalle_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
// Leo el Data key con el que estoy trabajando
int consultaId = (int)solucionDetalle.DataKey.Value;
// Find the TextBox controls with updated data
TextBox nuevaSolucionTextBox = (TextBox)solucionDetalle.FindControl("solucionText Box");
// Extract the updated data from the TextBoxes
string newSolucion = nuevaSolucionTextBox.Text;

// Define data objects
SqlConnection conn;
SqlCommand comm;
// Initialize connection
string connectionString =
ConfigurationManager.ConnectionStrings[
"Pruebas"].ConnectionString;
// Initialize connection
conn = new SqlConnection(connectionString);
// Create command
comm = new SqlCommand("UPDATE SolucionConsultas SET Solucion=@Solucion WHERE ConsultaID=@ConsultaID",

conn);
// Add command parameters
comm.Parameters.Add("@ConsultaID", SqlDbType.Int);
comm.Parameters["@ConsultaID"].Value = consultaId;
comm.Parameters.Add("@Solucion", SqlDbType.NVarChar, 1000);
comm.Parameters["@Solucion"].Value = newSolucion;
//newSolucion;
// Enclose database code in Try-Catch-Finally
try
{
// Open the connection
conn.Open();
// Execute the command
comm.ExecuteNonQuery();
}
finally
{
// Close the connection
conn.Close();
}

//Exit edit mode
solucionDetalle.ChangeMode(DetailsViewMode.ReadOnl y);

// Reload the details view
BindSolucion();
}

protected void BindSolucion()
{
// El id de la consulta sera el DataKey para trabajar.
int consultaId = Convert.ToInt32(Request.QueryString["consultaID"]);
// Define data objects
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
// Read the connection string from Web.config
string connectionString =
ConfigurationManager.ConnectionStrings[
"Pruebas"].ConnectionString;
// Initialize connection
conn = new SqlConnection(connectionString);
//Variable del select
string selectSQL = "SELECT SolucionConsultas.Fecha, aspnet_Users.UserName, SolucionConsultas.Solucion, SolucionConsultas.ConsultaID FROM SolucionConsultas INNER JOIN aspnet_Users ON SolucionConsultas.UserID = aspnet_Users.UserID WHERE SolucionConsultas.ConsultaID = @ConsultaID";
// Create command
comm = new SqlCommand(selectSQL, conn);
// Add the ConsultaID parameter
comm.Parameters.Add("ConsultaID", SqlDbType.Int);
comm.Parameters["ConsultaID"].Value = consultaId;
// Enclose database code in Try-Catch-Finally
try
{
// Open the connection
conn.Open();
// Execute the command
reader = comm.ExecuteReader();
// Fill the grid with data
solucionDetalle.DataSource = reader;
solucionDetalle.DataKeyNames = new string[] { "ConsultaID" };
solucionDetalle.DataBind();
// Close the reader
reader.Close();
}
finally
{
// Close the connection
conn.Close();
}
}

*********************************************

No se que puede estar pasando.

Muchas gracias por su ayuda.