Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente bannato
    Registrato dal
    Jun 2004
    Messaggi
    1,117

    Calendario in righe di un datagrid

    Ciao a tutti, vorrei inserire un js per la visualizzazione di un calendario in tutte le righe di un datagrid:

    ad ogni click sull'immagine dovrei poter inserire nel textbox della riga, la data selezionata (ovviamente solo nel textbox della riga)

    il codice (che funziona in un form tradizionale) è il seguente (non so come inserirlo nelle righe del datagrid)

    <ItemTemplate>
    <asp:TextBox ID="Data" runat="server" Width="80" MaxLength="10" Cssclass="TestoDataGrid" Text="" />

    [img]Images/cal.bmp[/img]
    <SCRIPT type="text/javascript">
    Calendar.setup({
    inputField : "Data", // id of the input field
    ifFormat : "%d/%m/%Y", // format of the input field
    button : "f_trigger_i", // trigger for the calendar (button ID)
    align : "Tl", // alignment (defaults to "Bl")
    singleClick : true
    });
    </SCRIPT>
    </ItemTemplate>


    ottengo come errore che value è nullo... il debug si ferma qui

    if (mustCreate)

    cal.create();

    ******* cal.parseDate(dateEl.value || dateEl.innerHTML);

    cal.refresh();



    ma non è sicuramente un problema di JS, dato che in un tutte le altre pagine funziona correttamente; quello che non riesco a capire è come gestire le righe del datagrid



    Grazie

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    19
    Io al posto di fare un js ho messo nel datagrid un calendar ed ho gestito tutto con le templatecolumn.

    Se ti puo' essere utile ti cerco il codice e ti preparo un'esempio.

  3. #3
    Utente bannato
    Registrato dal
    Jun 2004
    Messaggi
    1,117
    Mi faresti un grosso favore... almeno per confrontare le due soluzioni

    Thanks

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    19
    Ecco come ho fatto:

    Parte aspx

    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="GridCalendar.aspx.vb" Inherits="WebExapleVB.GridCalendar"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>GridCalendar</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="form_GridCalendar" method="post" runat="server">
    <asp:datagrid id="dgUtenti" AutoGenerateColumns="False" Runat="server" CssClass="grid" Font-Size="8pt"
    Font-Names="verdana" BorderColor="Black" BorderWidth="1px" CellPadding="4" ForeColor="Black"
    BackColor="#FFFFC0">
    <Columns>
    <asp:BoundColumn DataField="id" ReadOnly=True Visible=False></asp:BoundColumn>
    <asp:BoundColumn DataField="nome" ReadOnly="True" HeaderText="Nome"></asp:BoundColumn>
    <asp:BoundColumn DataField="cognome" ReadOnly="True" HeaderText="Cognome"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Data Compleanno">
    <ItemTemplate>
    <asp:Label text='<%#Databinder.Eval(Container.Dataitem, "DataCompleanno")%>' Runat=server>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:Calendar ID="calendario" Runat="server"></asp:Calendar>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Conferma" CancelText="Annulla" EditText="Data"></asp:EditCommandColumn>
    </Columns>
    </asp:datagrid>


    <asp:Label ID="lblMessage" Runat="server"></asp:Label>
    </form>
    </body>
    </HTML>

    Parte vb.net

    Imports System.Data
    Imports System.Data.sqlclient

    Public Class GridCalendar
    Inherits System.Web.UI.Page

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents dgUtenti As System.Web.UI.WebControls.DataGrid
    Private strConn As String = "APPLICATION NAME=Datagrid; DATA SOURCE=MICHELANGELO; DATABASE=GestUtenti; USER ID=sa; PASSWORD=hpxw6000sql"
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    If Not IsPostBack Then
    Bind_Grid()
    End If
    End Sub

    Private Sub Bind_Grid()
    Dim tabellaUtenti As DataTable
    'Controllo la sessione per verificare se e' presente la tabella
    tabellaUtenti = Session("tblUsers")
    If tabellaUtenti Is Nothing Then
    Dim objConn As New SqlConnection
    objConn.ConnectionString() = strConn
    Dim objCommand As New SqlCommand
    objCommand.CommandText = "CARICA_UTENTI"
    objCommand.CommandType = CommandType.StoredProcedure
    objCommand.Connection = objConn
    Dim objAdapter As New SqlDataAdapter
    objAdapter.SelectCommand = objCommand
    tabellaUtenti = New DataTable
    Try
    Try
    objAdapter.Fill(tabellaUtenti)
    Finally
    objConn.Dispose()
    End Try
    Catch ex As Exception
    lblMessage.Text = "Errore"
    Finally
    objConn = Nothing
    objAdapter = Nothing
    End Try
    tabellaUtenti.Columns.Add("cols")
    tabellaUtenti.AcceptChanges()
    'Metto la tabella in sessione
    Session("tblUsers") = tabellaUtenti
    End If
    'Associo la tabella al datagrid
    dgUtenti.DataSource = tabellaUtenti
    dgUtenti.DataBind()
    End Sub

    Private Sub dgUtenti_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgUtenti.EditCommand
    dgUtenti.EditItemIndex = e.Item.ItemIndex
    Bind_Grid()
    End Sub

    Private Sub dgUtenti_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgUtenti.CancelCommand
    dgUtenti.EditItemIndex = -1
    Bind_Grid()
    End Sub

    Private Sub dgUtenti_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgUtenti.UpdateCommand
    Dim id_record As String = e.Item.Cells(0).Text
    Dim dataC As Date = CDate(CType(e.Item.Cells(4).FindControl("calendari o"), Calendar).SelectedDate)
    Memorizza_Data(id_record, dataC)
    dgUtenti.EditItemIndex = -1
    Bind_Grid()
    End Sub

    Private Sub Memorizza_Data(ByRef id_record As Int32, ByRef dataC As Date)
    Dim tabellaUtenti As DataTable = Session("tblUsers")
    For Each row As DataRow In tabellaUtenti.Rows
    If row("id") = id_record Then
    row("DataCompleanno") = dataC
    Exit For
    End If
    Next
    Session("tblUsers") = tabellaUtenti
    tabellaUtenti = Nothing
    End Sub
    End Class

    Nel mio caso ho usato una tabella che metto in sessione, ma nessuno ti vieta di aggiornare direttamente la sorgente dati.

    Ciao,
    Luca.

  5. #5
    Utente bannato
    Registrato dal
    Jun 2004
    Messaggi
    1,117
    grazie 1000

    domani provo ...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.