I converted a boundfield into a templatefield
The templatefield now looks like this
<asp:TemplateField HeaderText="Quantity">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Quantity") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Quantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
The sub below used to work for the boundfield
Protected Sub CartGrid_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
Dim QuantityTextBox As TextBox = CType(CartGrid.Rows(e.RowIndex).Cells(2).Controls(0), TextBox)
Dim Quantity As Integer = Convert.ToInt32(QuantityTextBox.Text)
If Quantity = 0 Then
Profile.Cart.Items.RemoveAt(e.RowIndex)
Else
Profile.Cart.Items(e.RowIndex).Quantity = Quantity
End If
CartGrid.EditIndex = -1
BindGrid()
End Sub
But now it spits out the error
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
thanks.
The templatefield now looks like this
<asp:TemplateField HeaderText="Quantity">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Quantity") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Quantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
The sub below used to work for the boundfield
Protected Sub CartGrid_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
Dim QuantityTextBox As TextBox = CType(CartGrid.Rows(e.RowIndex).Cells(2).Controls(0), TextBox)
Dim Quantity As Integer = Convert.ToInt32(QuantityTextBox.Text)
If Quantity = 0 Then
Profile.Cart.Items.RemoveAt(e.RowIndex)
Else
Profile.Cart.Items(e.RowIndex).Quantity = Quantity
End If
CartGrid.EditIndex = -1
BindGrid()
End Sub
But now it spits out the error
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
thanks.