We would like to populate a textbox with today's date as a default value when the user goes into "Add" mode on an ASP.Net DetailsView from a VB.Net code-behind file. Can you show me how to get it populated?
Here is the markup for the textbox we wish to populate:
<asp:TemplateField HeaderText="Late Time Arrived At School:" SortExpression="LateTimeArrivedAtSchool">
<EditItemTemplate>
<asp:TextBox ID="TextBoxLateTimeArrivedAtSchool" runat="server"
Text='<%# Bind("LateTimeArrivedAtSchool", "{0:hh:mm}") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBoxLateTimeArrivedAtSchool" runat="server"
Text='<%# Bind("LateTimeArrivedAtSchool", "{0:hh:mm}") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelLateTimeArrivedAtSchool" runat="server"
Text='<%# Bind("LateTimeArrivedAtSchool", "{0:hh:mm}") %>'></asp:Label>
</ItemTemplate>
<ItemStyle ForeColor="Blue" />
</asp:TemplateField>
We also have set up OnItemCommand as shown in this markup:
<asp:DetailsView
ID="DetailsView"
runat="server"
AutoGenerateRows="False"
Height="50px"
Width="207px"
DataSourceID="SqlDataSourceDetails"
DataKeyNames="ID"
OnItemCommand="DetailsViewDetails_ItemCommand">
<Fields>
The code-behind file has this coding:
Protected Sub DetailsViewDetails_ItemCommand(sender As Object, e As System.Web.UI.WebControls.DetailsViewCommandEventArgs)
Select Case e.CommandName
Case "Add"
Case "Edit"
ButtonAddNewAttendance.Enabled = False
Case "Delete"
Case "Update"
ButtonAddNewAttendance.Enabled = True
Case "Insert"
End Select
End Sub
I tried to type TextBoxLateTimeArrivedAtSchool.Text in the Case -> "Add" but got a message that TextBoxLateTimeArrivedAtSchool was not defined. I'm not sure why intellisence did not find it from the markup.
I was thinking Case -> "Add" was the correct place to populate the textbox but looks like that's not the place to do it.
I think you have to find the control first. The code should be something like this:
Select Case e.CommandName
Case "Add"
Dim txtBox As TextBox
textBox = DetailsViewDetails.FindControl("TextBoxLateTimeArrivedAtSchool")
textBox.Text = DateTime.Now
Related
I have following gridview in aspx page:
<asp:GridView Runat="server" id="gv1" PageSize="20" Visible="False" AllowPaging="True" Width="100%"
CssClass="clsDataGrid" AutoGenerateColumns="false" DataKeyNames="intProofSLNo,txtAdminRemarks" CommandArgument='Eval(intProofSLNo,txtAdminRemarks)'
OnRowCommand="gv1_RowCommand" OnRowDataBound ="gv1_OnRowDataBound" >
<asp:BoundField DataField="intProofSLNo" ReadOnly="True" Visible="false" ItemStyle-Wrap="false" HeaderText="Sl No" ItemStyle-CssClass="clsNormalText"></asp:BoundField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="lnkbtnApprove" runat="server" CommandName="Approve" Text= "Approve / " />
<asp:LinkButton ID="lnkbtnReject" runat="server" CommandName="Reject" Text= "Reject" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Admin Remarks">
<ItemTemplate>
<asp:Label ID="lblAdminRemarks" runat="server" ItemStyle-Wrap="True" Text='<%# Bind("txtAdminRemarks")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAdminRemarksEdit" runat="server" cssclass=clsCommonInput MaxLength="252" Text='<%# DataBinder.Eval(Container.DataItem, "txtAdminRemarks")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:LinkButton ID="lblEdit" runat="server" Text="Edit" ToolTip="Edit" CommandName="Edit" CommandArgument='<%# Container.DataItemIndex %>'>
</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" Width="38" runat="server" Text="Update|" CommandName="Update"CommandArgument='<%# Container.DataItemIndex %>' CausesValidation="true" ToolTip="Save"> </asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" Width="40" Text="Cancel" CommandName="Cancel"
CausesValidation="false" ToolTip="Reset"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The user clicks on the 'Edit' link which makes 'Update' and 'Cancel' links visible.It then enters the remarks in the textbox and clicks 'Update'.A row command event is fired which updates the remarks in DB for the entry in that particular row. The same event calls the bind function:
Protected Sub gv1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
If e.CommandName = "Update" Then
//some code to update remarks//
gv1.EditIndex = -1
subBindDataGrid()
End If
The subBindDataGrid() fires the following rowbound event which hides the buttons depending on admin remarks:
Protected Sub gv1_OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lblAdminRemarks As Label = DirectCast(e.Row.FindControl("lblAdminRemarks"), Label)
Dim lnkReject As LinkButton = DirectCast(e.Row.FindControl("lnkbtnReject"), LinkButton)
Dim lnkApprove As LinkButton = DirectCast(e.Row.FindControl("lnkbtnApprove"), LinkButton)
Dim lnkEdit As LinkButton = DirectCast(e.Row.FindControl("lblEdit"), LinkButton)
If DataBinder.Eval(e.Row.DataItem, "txtAdminRemarks").ToString().Trim = "Auto-Approved" Then
lnkApprove.Visible = False
lnkReject.Visible = False
lnkEdit.Visible = False
Else
lnkbtnApprove.Visible = True
lnkbtnReject.Visible = True
End If
End If
The remarks get updated in the DB. However, there is some issue in binding and instead of displaying the grid, the page is redirected to an error page. There is no exception thrown anywhere while debugging. The same events are also called in 'Edit'command. However, the functionality works fine there.Please suggest if there is anything wrong with the syntax.
I see you don't define a DataSourceID on the GridView static definition, please make sure you define a DataSource for the GridView in the subBindDataGrid procedure, otherwise it will have a null datasource in input.
Apologies for the slightly convoluted title.
Basically, I have a project where I have a database connected to it. I'm displaying some of the contents of the database using a GridView, which is all up and running, but the way I'm designing the page I need to be able to click a button in each row that in essence exports the value of one of the cells in the row to a subroutine.
I've tried googling it quite a bit and trying related things I found here, but nothing I could find would function like I would like it to.
The relevant code is below.
Markup:
<asp:GridView ID="Staffgv" runat="server" AutoGenerateColumns="false" OnRowCommand="Staffgv_RowCommand" AllowPaging="true" PageSize="20" OnPageIndexChanging="Staffgv_PageIndexChanging" BackColor="#f9f9f9" CssClass="gvStyle" >
<Columns>
<asp:TemplateField HeaderText="Start" InsertVisible="False" SortExpression="DateTimeStart">
<HeaderStyle Width="70px" CssClass="hdrGvStart"/>
<ItemTemplate>
<asp:Label ID="lblDateTimeStart" runat="server" Text='<%# Bind("DateTimeStart", "{0:t}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Finish" SortExpression="DateTimeEnd">
<HeaderStyle Width="70px" CssClass="hdrGvFinish"/>
<ItemTemplate>
<asp:Label ID="lblDateTimeEnd" runat="server" Text='<%# Bind("DateTimeEnd", "{0:t}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Forename" SortExpression="Forename">
<HeaderStyle Width="140px" CssClass="hdrGvForename"/>
<ItemTemplate>
<asp:Label ID="lblForename" runat="server" Text='<%# Bind("Forename") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Surname" SortExpression="Surname">
<HeaderStyle Width="140px" CssClass="hdrGvSurname"/>
<ItemTemplate>
<asp:Label ID="lblSurname" runat="server" Text='<%# Bind("Surname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle CssClass="gvHeaderEdit" />
<ItemTemplate>
<asp:Button ID="Btnapptid" runat="server" Text="" CssClass="btnGVEdit" CommandName="FillStaffTables" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And the relevant VB code:
Private Sub Staffgv_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles Staffgv.RowDataBound
Select Case e.Row.RowType
Case DataControlRowType.DataRow
Dim row = DirectCast(e.Row.DataItem, DataRowView)
Dim apptid As Integer = Integer.Parse(row("AppointmentID").ToString)
Dim Btnapptid = DirectCast(e.Row.FindControl("Btnapptid"), Button)
'Btnapptid.Text = apptid
Btnapptid.ToolTip = apptid
End Select
End Sub
Protected Sub Staffgv_RowCommand(ByVal sender As Object, e As GridViewCommandEventArgs)
If (e.CommandName = "FillStaffTables") Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
lblTxtTester.Text = "AppointmentID"
TextboxTester.Text = index
End If
End Sub
If anyone would like more code like the code used to fill the GridView I'll post it, just didn't want to post too much irrelevant code.
Thanks
Solution A
When you only want 1 value from the gridview row when the button is clicked.
You could simply utilize the CommandArgument of your button (Btnapptid). This assumes that you don't need the gridview row index for when the button is clicked. If you do need this, then please see Solution B, otherwise continue here.
First, you'd need to modify your button's CommandArgument in the aspx page
ASPX
<asp:Button ID="Btnapptid" runat="server" Text="" CssClass="btnGVEdit"
CommandName="FillStaffTables" CommandArgument='<%# Bind("AppointmentID") %>'/>
Then you should be able to grab the AppointmentID like this
VB (inside Staffgv_RowCommand())
If (e.CommandName = "FillStaffTables") Then
txtAppointmentID.Text = e.CommandArgument
End If
Solution B
When you need more than 1 value from the gridview row when the button is clicked
Please note that this solution requires a couple changes on your end
Create an additional control (in the gridview) which should hold the value that you want to get when the button is clicked.
Fill said control with the value you want (via Bind() in the UI or in RowDataBound in the codebehind).
Next, in your RowCommand you'd be able to grab the newly created control with the help of the index variable (from your example) like so
Staffgv.Rows(index).FindControl("YOUR_CONTROLS_ID")
Example
Say that you decide to create a HiddenField control in which to store the value from your database
ASPX (hidden field should be somewhere inside the gridview - right under Btnapptid should be fine)
<asp:HiddenField ID="hfMyControl" runat="server" Visible="False"
Value='<%# Bind("SOME_DB_COLUMN") %>'/>
VB (inside Staffgv_RowCommand())
Dim hfMyControl As HiddenField = _
DirectCast(Staffgv.Rows(index).FindControl("hfMyControl"), HiddenField)
Then simply use the value of hfMyControl
hfMyControl.Value
You could also repeat all this using multiple controls in order to potentially access multiple DB values stored in controls in the gridview.
I have a GridView that contains DropDownLists. They function as expected except during page postback. When the user clicks the update button on the page, I have a sub that loops through the grid rows, performs business ops and saves the data.
The problem is that during postback, the DropDownLists' selected properties do not represent that changes to selections made by the user. The selected item shows 'Dirty = True' in the break point.
Here is a subset of the code I use for reference:
<asp:GridView ID="materialGridView" runat="server"
AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="MaterialTypeName" HeaderText="Material Type" />
<asp:TemplateField>
<HeaderTemplate>
Quantity
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="quantityTextBox" runat="server" Width ="50" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Material
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList ID="materialDropDownList" runat="server" Width="200">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Color
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="colorTextBox" runat="server" Width="100" BackColor="BlanchedAlmond" ReadOnly="true" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
RBK
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButton id="rbkRadioButton" runat="server" Checked="true" />
<asp:TextBox ID="rbkPriceTextBox" runat="server" Width="50" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Wimsatt
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="wimsattPriceTextBox" runat="server" Width="50"></asp:TextBox>
<asp:RadioButton id="wimsattRadioButton" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
For Each row As GridViewRow In materialGridView.Rows
With row
materialDropDownList = DirectCast(.FindControl("materialDropDownList"), DropDownList)
quantityTextBox = DirectCast(.FindControl("quantityTextBox"), TextBox)
rbkPriceTextBox = DirectCast(.FindControl("rbkPriceTextBox"), TextBox)
wimsattPriceTextBox = DirectCast(.FindControl("wimsattPriceTextBox"), TextBox)
colorTextBox = DirectCast(.FindControl("colorTextBox"), TextBox)
rbkRadioButton = (DirectCast(.FindControl("rbkRadioButton"), RadioButton))
'compare current selecton in drop down and update if nessisary
For Each materialTableRow As DataRow In materialTable.Rows
'the item we are on is the item selected ANDALSO it is not yet assigned to the quote, so it's a new selection, update pricing.
Dim materialTableRowMaterialID As String = bizClass.dbCStr(materialTableRow.Item("MaterialID"))
If materialTableRowMaterialID = materialDropDownList.SelectedValue Then
If IsDBNull(materialTableRow.Item("QuoteID")) Then
rbkPriceTextBox.Text = bizClass.dbCStr(materialTableRow.Item("RBK"))
wimsattPriceTextBox.Text = bizClass.dbCStr(materialTableRow.Item("Wimsatt"))
End If
End If
Next materialTableRow
If rbkRadioButton.Checked = True Then
materialCostSumDecimal += bizClass.strToDec(quantityTextBox.Text) * bizClass.strToDec(rbkPriceTextBox.Text)
chosenSupplierString = "RBK"
Else
materialCostSumDecimal += bizClass.strToDec(quantityTextBox.Text) * bizClass.strToDec(wimsattPriceTextBox.Text)
chosenSupplierString = "Wimsatt"
End If
End With 'row
First of all make sure you are not binding the gridview on postback before reading dropdown values, because databind causes all controls to lose their postback value.
Second gridview is only able to postback the value of the only row that is being edited, so what you need to do is to move the dropdown (and all other controls) to the EditTemplate and set the row mode to Edit so the value will get posted back to server.
But if you want to be able to change all the dropdowns in all rows you might need to use Repeater control instead of GridView.
I am new to Vb.net.
I am using gridview and binding it a resultset from database. I am trying to use asp button and associate a codebehind function with it.
But since the rows are generating dynamically, ids of button are incrementing accordingly.
Here is the code -
'<asp:GridView ID="grdProjects" runat="server" CssClass="q_acontent" Width="990px"
AutoGenerateColumns="false" CellPadding="2" ClientIDMode="static" ViewStateMode="Enabled">
<asp:TemplateField HeaderText="Document Name">
<ItemTemplate>
<asp:Button ID="Button3" runat="server" Text='<%# (Convert.ToString(DataBinder.Eval(Container.DataItem, "Data_text")))%>'/>
</ItemTemplate>
<ItemStyle Width="5%" HorizontalAlign="Center" CssClass="conatact_phone breakword" />
</asp:TemplateField>
</asp:GridView>'
Please help me how to associate codebehind function and pass its corresponding button text to it.
Use the OnCommand event of button controls and Set the CommandArgument property of the button to your DataItem value as:
<ItemTemplate>
<asp:Button ID="Button3" runat="server"
Text='<%# (Convert.ToString(DataBinder.Eval(Container.DataItem,"Data_text")))%>'
OnCommand="Button3_Command"
CommandArgument='<%# (Convert.ToString(DataBinder.Eval(Container.DataItem,
"Data_text")))%>'
/>
</ItemTemplate>
OnCommand event in your code behind file:
Public Sub Button3_Command(sender As Object, e As CommandEventArgs)
Dim _dataText As String = e.CommandArgument.ToString()
End Sub
I've been trying to make use of DetailsView for the past few days to show and edit data from a single record taken from a GridView, both read their datafrom an SqlDataSource.
I've been searching the internet and the MSDN for info about how to use a DetailsView to edit data and I managed to cobble something together, the problem is that apparently the actual updating method doesn't run.
So here's an extract of my code
GridView In the page:
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DefaultMode="Edit">
<fields>
<asp:TemplateField HeaderText="Codice Cliente">
<ItemTemplate>
<asp:Label ID="lblCliCod" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cli_cod") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCliCod" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cli_cod")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Descrizione">
<ItemTemplate>
<asp:Label ID="lblCliDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cli_desc")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCliDesc" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cli_desc")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nome Utente">
<ItemTemplate>
<asp:Label ID="lblCliUser" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cli_user")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCliUser" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cli_user")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password">
<ItemTemplate>
<asp:Label ID="lblCliPass" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cli_pass")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCliPass" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cli_pass")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amministratore">
<ItemTemplate>
<asp:Label ID="lblCliAdmin" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.cli_admin")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="chkCliAdminE" runat="server" Text='<%# CBool(DataBinder.Eval(Container, "DataItem.cli_admin"))%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<EditItemTemplate>
<asp:LinkButton Text="Aggiorna" ID="UpdateButton" runat="Server" CommandName="Update"></asp:LinkButton>
<asp:LinkButton Text="Elimina" ID="DeleteButton" runat="server" CommandName="Edit"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</fields>
</asp:DetailsView>
Relevant parts of the Codebehind:
Private Sub SetupDataSource() 'this is the sqldatasource I'm using for the detailsview
SqlDataSource2.ConnectionString = Assist.connectionString
SqlDataSource2.SelectCommand = detailsSelect
SqlDataSource2.SelectParameters.Add(New Parameter("id"))
SqlDataSource2.UpdateCommand = detailsUpdate
SqlDataSource2.UpdateParameters.Add(New Parameter("cli_cod"))
SqlDataSource2.UpdateParameters.Add(New Parameter("cli_desc"))
SqlDataSource2.UpdateParameters.Add(New Parameter("cli_user"))
SqlDataSource2.UpdateParameters.Add(New Parameter("cli_pass"))
SqlDataSource2.UpdateParameters.Add(New Parameter("cli_admin"))
End Sub
Private Sub SetupDetailsView(id As Int32)
DetailsView1.AutoGenerateRows = False
DetailsView1.DataSource = SqlDataSource2
SqlDataSource2.SelectParameters("id").DefaultValue = id
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
cn.Open()
SetupDataSource()
If Not IsPostBack Then
Dim id As String = Request.QueryString("id")
If id <> "" Then
SetupDetailsView(id)
DetailsView1.DataBind()
End If
End If
End Sub
Protected Sub DetailsView1_ItemUpdating(sender As Object, e As DetailsViewUpdateEventArgs) Handles DetailsView1.ItemUpdating
Dim cliCod As String = (CType(DetailsView1.FindControl("txtCliCod"), TextBox)).Text.ToString()
Dim cliDesc As String = (CType(DetailsView1.FindControl("txtCliDesc"), TextBox)).Text.ToString()
Dim cliUser As String = (CType(DetailsView1.FindControl("txtCliUser"), TextBox)).Text.ToString()
Dim cliPass As String = (CType(DetailsView1.FindControl("txtCliPass"), TextBox)).Text.ToString()
Dim cliAdmin As Boolean = If((CType(DetailsView1.FindControl("chkCliAdminE"), CheckBox)).Checked = True, True, False)
SqlDataSource2.UpdateParameters("cli_cod").DefaultValue = cliCod
SqlDataSource2.UpdateParameters("cli_desc").DefaultValue = cliDesc
SqlDataSource2.UpdateParameters("cli_user").DefaultValue = cliUser
SqlDataSource2.UpdateParameters("cli_pass").DefaultValue = cliPass
SqlDataSource2.UpdateParameters("cli_Admin").DefaultValue = If(cliAdmin = True, "1", "0")
DetailsView1.DataBind()
End Sub
I'm either missing something or doing it wrong somewhere, which one is it and why?
I'm not an expert at using SqlDataSource, but you might try inserting a SqlDataSource.Update in your Item_Updating method:
SqlDataSource2.UpdateParameters("cli_cod").DefaultValue = cliCod
SqlDataSource2.UpdateParameters("cli_desc").DefaultValue = cliDesc
SqlDataSource2.UpdateParameters("cli_user").DefaultValue = cliUser
SqlDataSource2.UpdateParameters("cli_pass").DefaultValue = cliPass
SqlDataSource2.UpdateParameters("cli_Admin").DefaultValue = If(cliAdmin = True, "1", "0")
SqlDataSource2.Update();
DetailsView1.DataBind()
I use a DetailsView in an ongoing project. They are finicky, but they work great when set up correctly.
Several potential issues I can see with your DetailsView are:
Eval vs Bind
As with all databound controls, Databinder.Eval is a read-only databind method. To allow controls to automatically update, you must use Bind in the edit template. Of course, you can manually update your database, but why reinvent the wheel?
<asp:TemplateField HeaderText="Codice Cliente">
<ItemTemplate>
<asp:Label ID="lblCliCod" runat="server" Text='<%# Eval("DataItem.cli_cod") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCliCod" runat="server" Text='<%# Bind("DataItem.cli_cod")%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
Built-in Update functionality vs manual update functionality
You don't really need to use DetailsView1_ItemUpdating unless you are want to catch and modify values after submit and before committing to the datasource. i.e. concatenating individual year/month/day textboxes into a single date.
However, since you are not currently generating an Update button (using property AutoGenerateEditButton="True"), you may need to handle the update manually as you are attempting. Alternatively, for basic binding and update, I would comment out the updating functions, add the autogenerateeditbutton="True" property, and then try updating.
Primary Key
With some datasources, you must specify the DataKeyNames property (your primary key/s of your datasource) on the DetailsView to enable auto-binding. I don't know for sure, but you may also need to set the DefaultMode property.
All properties and methods are explained well on the MSDN DetailsView page, but it's rather verbose. The MSDN Updating a DetailsView page is more concise