• Jueves 2 de Mayo de 2024, 05:55

Autor Tema:  listview - comportamiento extraño  (Leído 1216 veces)

leitor79

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
listview - comportamiento extraño
« en: Viernes 25 de Febrero de 2011, 05:14 »
0
Estoy intentando enlazar un dataset a un listview. A pesar de que los ejemplos que he conseguido en la web funcionan bien, estos son enlazados a otra cosa y, cuando realizo las modificaciones para enlazarlo a un dataset, persiste el problema. Lo raro es que he tomado 3 casos de la web, utilizando 3 webforms nuevos para cada uno, y el problema se repite.

Realizo las modificaciones para enlazarlo a mi dataset y representarlo de forma en que lo describí y se muestra correctamente (veo mis datos y los botones). Lo que sucede es lo siguiente:

- Al hacer click en "editar", la primera vez nunca lo toma. A partir de la segunda vez en adelante, sí.

- Luego de que estoy en modo edición, no puedo salir de éste ni presionando el botón "cancelar" ni "actualizar". Se queda en el edititemtemplate.

Debajo les pego mi código. Les comento que, aunque no está en el código que pego (para no ocupar espacio de más), declaré todos los eventos del tipo ItemEditing, ItemUpdating, etc etc, pues me daba error si no estaban declarados. Están declarados, pero vacíos.

Muchas gracias por su ayuda!

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim da As SqlDataAdapter
        Dim con As SqlConnection
        Dim ds As System.Data.DataSet
       
        Dim s As String

        If Not IsPostBack Then
            s = "DATA SOURCE=00.00.00.00;USER ID=xxx;PASSWORD=xxx;INITIAL CATALOG=xxx;"
            ds = New System.Data.DataSet
            con = New SqlConnection(s)


            da = New SqlDataAdapter("select * from vehiculos", con)
            da.Fill(ds)

            lstVehiculos.DataSource = ds.Tables(0)
            lstVehiculos.DataBind()


        End If


    End Sub


   
   
   <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "EDITADO PORQUE NO TENGO PERMISOS PARA POSTEAR LINKS">

<html xmlns="EDITADO PROQUE NO TENGO PERMISOS PARA POSTEAR LINKS">
<head runat="server">
    <title></title>

  <script type="text/css">

             body
{
}

table
{
        border-collapse:collapse;
        border-color:Black;  
}

tr
{
    border-width:1;    
    border-color:Black;
    height:20px;    
}

th
{
    background-color: #507CD1;  
    font-family: Tahoma;
    font-size: small;
    color : #ffffff;  
    border-width:1;
}

td
{
    font-family: Tahoma;
    font-size: small;  
    border-width:1;
    border-color:Black;  
}
input
{
    font-family: Tahoma;    
    height:20px;
}

.button {
    border: 1px solid #006;
    background: #ccf;
}
.button:hover {
    border: 1px solid #f00;
    background: #eef;
    }
    </script>

</head>
<body>
               
    <form id="form1" runat="server">

    <div>
       
           
           <asp:ListView ID="lstVehiculos" runat="server">
            <LayoutTemplate>
                <table border="0" cellpadding="1">
                    <tr style="background-color:#E5E5FE">
                        <th align="left"><asp:Label ID="Label1" runat="server" Text="Ir"></asp:Label></th>
                        <th align="left"><asp:LinkButton ID="lnkNombre" runat="server" CommandName="Ordenar" CommandArgument="ID">Vehículo</asp:LinkButton></th>
                        <th align="left"><asp:Label ID="Label2" runat="server" Text="Editar"></asp:Label></th>
                        <th align="left"><asp:Label ID="Label3" runat="server" Text="Borrar"></asp:Label></th>
                    </tr>
                    <tr id="itemPlaceholder" runat="server"></tr>
                </table>
                <asp:DataPager ID="ItemDataPager" runat="server" PageSize="5">
                    <Fields>
                        <asp:NumericPagerField ButtonCount="2" />
                    </Fields>
                </asp:DataPager>    
            </LayoutTemplate>




           
            <ItemTemplate>
                    <tr>
                        <td align="center"><asp:Imagebutton ID="Imagebutton1" runat="server" CommandName="Ir"  ImageUrl="images/go.ico" CommandArgument=' <%# Eval("VehiculoID")%>' ></asp:Imagebutton></td>
                        <td><%# Eval("VehiculoNombre")%></td>
                        <td align="center"><asp:Imagebutton ID="Imagebutton2" runat="server" CommandName="Edit" ImageUrl="images/edit.ico" CommandArgument=' <%# Eval("VehiculoID")%>' ></asp:Imagebutton></td>
                        <td align="center"><asp:Imagebutton ID="Imagebutton3" runat="server" CommandName="Delete" ImageUrl="images/recycle.ico" CommandArgument=' <%# Eval("VehiculoID")%>' ></asp:Imagebutton></td>
                    </tr>
            </ItemTemplate>
           
            <EditItemTemplate>
                <tr>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="txtVehiculo" runat="server" Text='<%# Eval("VehiculoNombre") %>'></asp:TextBox>                  
                    </td>
                   
                            <td align="center"><asp:Imagebutton ID="Imagebutton2" runat="server" CommandName="Update" ImageUrl="images/aceptar.ico" CommandArgument=' <%# Eval("VehiculoID")%>' ></asp:Imagebutton></td>
                        <td align="center"><asp:Imagebutton ID="Imagebutton3" runat="server" CommandName="Cancel" ImageUrl="images/cancelar.ico" CommandArgument=' <%# Eval("VehiculoID")%>' ></asp:Imagebutton></td>
                   

                </tr>
            </EditItemTemplate>

            <InsertItemTemplate>
                <tr id="Tr1" runat="server">
                    <td></td>
                    <td>
                        <asp:TextBox ID="txtFname" runat="server" Text='<%#Eval("VehiculoNombre") %>' Width="100px">First Name</asp:TextBox>
                        <asp:TextBox ID="txtLname" runat="server" Text='<%#Eval("VehiculoNombre") %>' Width="100px">Last Name</asp:TextBox>
                    </td>
                    <td><asp:TextBox ID="txtCtype" runat="server" Text='<%#Eval("VehiculoNombre") %>' Width="100px">Contact Type</asp:TextBox></td>
                     <td><asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /></td>
                   
                </tr>
            </InsertItemTemplate>
           
        </asp:ListView>
    </div>
   
    </form>
</body>
</html>