I've a dg with two template columns that have a textbox control. So, when the user click in a separate button for update the values don't are update, just when him insert a new record. Weel, I need that this code can update all my rows in my dg altomatically
when a user click in this button. There is my code; Sub Button1_Click(sender As Object, e As EventArgs) Dim di As DataGridItem ' Loop through the items in the datagrid. For Each di In dgBasket.Items ' Make sure this is an item and not the header or footer.
If di.ItemType = ListItemType.Item OrElse di.ItemType = ListItemType.AlternatingItem Then ' Get the current row for update or delete operations later. dgBasket.SelectedIndex = di.ItemIndex Dim Est As Integer = dgBasket.Items(dgBasket.SelectedIndex).Cells(7).Text
Dim id As Integer = di.ItemIndex Dim Qtd As Integer = "10" 'Ctype(di.Cells(2).Controls(0), TextBox).Text Dim Base As String = dgBasket.Items(dgBasket.SelectedIndex).Cells(3).Text Dim Bruto As Decimal = Qtd * Base Dim Desc As Decimal = "15" 'Ctype(di.Cells(5).Controls(0),
TextBox).Text Dim Liquido As Decimal = Bruto*(1-(Desc/100)) Dim DesEst As Decimal = dgBasket.Items(dgBasket.SelectedIndex).Cells(9).Text Dim PrcFull As Decimal = dgBasket.Items(dgBasket.SelectedIndex).Cells(10).Text If Qtd < 3 Then lblMsgBasket.Text = "Quantidade
abaixo do permitido." ElseIf Qtd > Est Then lblMsgBasket.Text = "Quantidade informada acima da disponível. "&Est ElseIf Desc > 50 Then lblMsgBasket.Text = "Desconto informado acima do permitido." ElseIf DesEst > 0 AndAlso Desc > 0 Then Liquido = Qtd*(PrcFull*(1-(Desc/100)))
Dim Venda As Decimal = Liquido/Qtd Bruto = Venda * Qtd ChangeQuantity(id, Qtd, Venda, Bruto, Desc, Liquido) lblMsgBasket.Text = "Clique em atualizar para recalcular o valor." lblvlrTotal.Visible = true lblValor.Visible = true dgBasket.SelectedIndex = -1 Else
Base = PrcFull*(1-(DesEst/100)) ChangeQuantity(id, Qtd, Base, Bruto, Desc, Liquido) lblMsgBasket.Text = "Clique em Atualizar para recalcular o valor." lblvlrTotal.Visible = true lblValor.Visible = true Session("Information") = "" dgBasket.SelectedIndex = -1
End If ' See if this one needs to be deleted. If CType(di.FindControl("chkDelete"), CheckBox).Checked Then 'delete checked rows Else 'Update the row instead. End If End If Next End Sub If someone can help me, I thank's, regards,
mroza714
Member
155 Points
31 Posts
Updating rows in template comlumns
Nov 13, 2003 07:35 PM|LINK
mroza714@msn.com