Foros del Web » Programación para mayores de 30 ;) » .NET »

Edit, Update, Cancel + Gridview

Estas en el tema de Edit, Update, Cancel + Gridview en el foro de .NET en Foros del Web. Alguien De Ustedes Tiene Un Ejemplo De Edicion De Registros Con El Gridview A Traves De Codigo? No Usando Los Famosos Controlsitos Sqldatasource O Programando ...
  #1 (permalink)  
Antiguo 16/04/2007, 10:00
 
Fecha de Ingreso: agosto-2006
Ubicación: en lima peru
Mensajes: 184
Antigüedad: 17 años, 8 meses
Puntos: 0
Edit, Update, Cancel + Gridview

Alguien De Ustedes Tiene Un Ejemplo De Edicion De Registros Con El Gridview A Traves De Codigo? No Usando Los Famosos Controlsitos Sqldatasource O Programando En El Aspx Sino En El Code Behind A Codigo Puro, Se Los Agradeceria.
  #2 (permalink)  
Antiguo 16/04/2007, 12:46
 
Fecha de Ingreso: agosto-2006
Ubicación: en lima peru
Mensajes: 184
Antigüedad: 17 años, 8 meses
Puntos: 0
Re: Edit, Update, Cancel + Gridview

Cita:
Iniciado por programadorvip Ver Mensaje
Alguien De Ustedes Tiene Un Ejemplo De Edicion De Registros Con El Gridview A Traves De Codigo? No Usando Los Famosos Controlsitos Sqldatasource O Programando En El Aspx Sino En El Code Behind A Codigo Puro, Se Los Agradeceria.

bueno estuve viendo por las webs y deseo convertir una celda en un control alguien tiene idea?¿?¿

Código:
   If e.CommandName = "Edit" Then
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)
            Dim customersGridView As GridView = CType(e.CommandSource, GridView)
            Dim row As GridViewRow = customersGridView.Rows(index)
            ' MsgBox(CStr(row.Cells.Item(3).Controls(0).ToString()))

            Dim txt As TextBox = CType(row.Controls.Item(4), TextBox)
            ' Session("t2") = CType(row.Cells(4).Controls(4), TextBox)
            ' Session("t3") = CType(row.Cells(6).Controls(6), TextBox)
            ' Session("t4") = CType(row.Cells(5).Controls(5), TextBox)
            ' wsUpdate.Credentials = System.Net.CredentialCache.DefaultCredentials
            Dim cad As String
            Try
                'cad = (wsUpdate.Actualizar_DIARIOS(Session("Id_Empresa"), t1.Text, t2.Text, t3.Text, 0, 0, 0, 0, 0, 0, 0, 0, 0, t4.Text, 0, 0, "", 0, 0, ""))
                GvdAsientos.EditIndex = -1
                DSDiarios.Merge(ws.Get_Diarios(Session("Id_Empresa")))

                GvdAsientos.DataSource = DSDiarios
                Me.GvdAsientos.DataBind()
                Me.tb_error.Text = cad

            Catch ex As Exception
                Response.Redirect("Wfrm_Error.aspx")
                Session("error") = ex.Message
            End Try
        End If
  #3 (permalink)  
Antiguo 16/04/2007, 13:05
 
Fecha de Ingreso: agosto-2006
Ubicación: en lima peru
Mensajes: 184
Antigüedad: 17 años, 8 meses
Puntos: 0
Re: Edit, Update, Cancel + Gridview

una pregunta como convierto una celda en un objeto??¿

If e.CommandName = "Edit" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = GvdAsientos.Rows(index)
Dim t1 As TextBox = CType(row.Cells.Item(3).Controls(0), TextBox)
Dim t2 As TextBox = CType(row.Cells.Item(4).Controls(0), TextBox)
Dim t3 As TextBox = CType(row.Cells.Item(6).Controls(0), TextBox)
Dim t4 As TextBox = CType(row.Cells.Item(5).Controls(0), TextBox)
End If

alguien me ayuda?
  #4 (permalink)  
Antiguo 17/04/2007, 10:58
Avatar de coronajc  
Fecha de Ingreso: abril-2007
Ubicación: Morelia, Michoacán
Mensajes: 6
Antigüedad: 17 años, 1 mes
Puntos: 0
Re: Edit, Update, Cancel + Gridview

No se si sea lo que buscas pero yo hago esto para convertir las celdas en labels

GridViewRow gv = GridView1.Rows[e.RowIndex];
Label lb = (Label)gv.FindControl("Label9");
  #5 (permalink)  
Antiguo 18/04/2007, 16:50
 
Fecha de Ingreso: agosto-2006
Ubicación: en lima peru
Mensajes: 184
Antigüedad: 17 años, 8 meses
Puntos: 0
De acuerdo Re: Edit, Update, Cancel + Gridview

BUENO, YA QUE ESTUVE BUSCANDO INFORMACION Y QUE NINGUN "TIGRE" ME AYUDO ACA LE ENVIO LA SOLUCION

CODE BEHIND
Código:
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
        SqlDataSource1 = New SqlDataSource("Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True", "SELECT EmployeeID, LastName, FirstName FROM employees")

        SqlDataSource1.DeleteCommand = "DELETE FROM Employees WHERE EmployeeID = @EmployeeID"
        SqlDataSource1.DeleteParameters.Add(New Parameter("EmployeeID", TypeCode.Int32))

        SqlDataSource1.InsertCommand = "INSERT INTO Employees (LastName, FirstName) VALUES (@LastName, @FirstName)"
        SqlDataSource1.InsertParameters.Add(New Parameter("LastName", TypeCode.String))
        SqlDataSource1.InsertParameters.Add(New Parameter("FirstName", TypeCode.String))


        SqlDataSource1.UpdateCommand = "UPDATE Employees SET LastName = @LastName, FirstName = @FirstName WHERE EmployeeID = @EmployeeID"
        SqlDataSource1.UpdateParameters.Add(New Parameter("LastName", TypeCode.String))
        SqlDataSource1.UpdateParameters.Add(New Parameter("FirstName", TypeCode.String))
        SqlDataSource1.UpdateParameters.Add(New Parameter("EmployeeID", TypeCode.Int32))

        If Not Page.IsPostBack Then
            EnlazarDatos()

        End If


    End Sub

    Private Sub EnlazarDatos()
        GridView1.DataSource = SqlDataSource1
        GridView1.DataBind()
    End Sub

    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        GridView1.EditIndex = -1
        EnlazarDatos()

    End Sub

    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        Dim fila As GridViewRow = GridView1.Rows(e.RowIndex)
        If Not (fila Is Nothing) Then
            SqlDataSource1.DeleteParameters("EmployeeID").DefaultValue = CType(fila.FindControl("Label3"), Label).Text

            SqlDataSource1.Delete()
            EnlazarDatos()
        End If

    End Sub

    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        GridView1.EditIndex = e.NewEditIndex
        EnlazarDatos()
    End Sub

    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim fila As GridViewRow = GridView1.Rows(e.RowIndex)
        If Not (fila Is Nothing) Then
            Dim lbl1 As New Label
            ' lbl1.Text = CType(fila.FindControl("Label1"), Label).Text
            'lbl1.Text = CType(fila.FindControl("TextBox1"), TextBox).Text
            SqlDataSource1.UpdateParameters("EmployeeID").DefaultValue = CType(fila.FindControl("TextBox3"), TextBox).Text
            SqlDataSource1.UpdateParameters("LastName").DefaultValue = CType(fila.FindControl("TextBox1"), TextBox).Text
            SqlDataSource1.UpdateParameters("FirstName").DefaultValue = CType(fila.FindControl("TextBox2"), TextBox).Text
            SqlDataSource1.Update()
            GridView1.EditIndex = -1
            EnlazarDatos()
        End If

    End Sub

    Protected Sub BTNAGREGAR_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        SqlDataSource1.InsertParameters("FirstName").DefaultValue = TextBox2.Text
        SqlDataSource1.InsertParameters("LastName").DefaultValue = TextBox1.Text

        SqlDataSource1.Insert()
        EnlazarDatos()
    End Sub
End Class

ARCHIVO ASPX, ESTOY USANDO AJAX, SCRIPT MANAGER Y UPDATEPANEL.

Código:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <div style="text-align: center">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <table style="width: 515px; height: 259px">
                            <tr>
                                <td style="width: 100px">
                                    LASTANAME</td>
                                <td style="width: 100px">
                                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
                                <td style="width: 100px">
                                    FIRSTNAME</td>
                                <td style="width: 100px">
                                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
                                <td style="width: 100px">
                                    &nbsp;<asp:Button ID="BTNAGREGAR" runat="server" OnClick="BTNAGREGAR_Click" Text="Button" />&nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td colspan="5">
                                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
                                        ForeColor="#333333" GridLines="None">
                                        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                                        <Columns>
                                            <asp:CommandField ShowEditButton="True" HeaderText="Operaciones" />
                                            <asp:CommandField ShowDeleteButton="True" />
                                            <asp:TemplateField HeaderText="CODIGO">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("EmployeeID") %>' ReadOnly="True"></asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("EmployeeID") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="APELLIDOS">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="NOMBRES">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                                        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                                        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                                        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                                        <AlternatingRowStyle BackColor="White" />
                                    </asp:GridView>
                                    <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </div>
    </form>
</body>
</html>
  #6 (permalink)  
Antiguo 15/11/2007, 20:21
 
Fecha de Ingreso: noviembre-2007
Mensajes: 1
Antigüedad: 16 años, 5 meses
Puntos: 0
De acuerdo Re: Edit, Update, Cancel + Gridview

Muchas gracias por subir este último código, no sabes lo que me has ayudado, esta genial... Mil gracias!!!!
  #7 (permalink)  
Antiguo 03/05/2012, 15:43
 
Fecha de Ingreso: septiembre-2007
Mensajes: 54
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Edit, Update, Cancel + Gridview

hay un problema si lo vez del punto de vista tu modificas y actualizas , directamente al la tabla de la base de datos ... si hay una forma de generar una tabla temporal con un datasource y actualiza esta table o dataset

podría contener todos los cambios en una datatable y al final colocar un boton guardar todoooo


Dim dv as DataView
Dim Table as DataTable
dv = CType(SqlDataSource1.Select(DataSourceSelectArgume nts.Empty), DataView)
Table = dv.Table()

si alguien tiene una forma de tabla temporal en una grilla sin estar recorriendo la gridview completamente seria genial
  #8 (permalink)  
Antiguo 03/05/2012, 15:44
 
Fecha de Ingreso: septiembre-2007
Mensajes: 54
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Edit, Update, Cancel + Gridview

http://www.microsoft.com/en-us/downl....aspx?id=23654 la base para que puedan ejecutar el ejemplo del colega ...ejecuten el srips de las carpetas despues de la instalacion
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 2 personas (incluyéndote)




La zona horaria es GMT -6. Ahora son las 08:49.