參考來源:Using GridView's EmptyDataTemplate to insert new row
--
精華段:
Sub ButtonEmptyInsert_Click(ByVal sender As Object, ByVal e As EventArgs)
' Insert new record
Dim RowIndex As Integer = DirectCast(DirectCast(sender, Control).NamingContainer, GridViewRow).RowIndex
Dim misship_id As DropDownList = TryCast(GridViewDetails.Rows(RowIndex).FindControl("DropListMisShipIDEmpty"), DropDownList)
Dim code_id As DropDownList = TryCast(GridViewDetails.Rows(RowIndex).FindControl("DropListCodeEmpty"), DropDownList)
Dim upc As TextBox = TryCast(GridViewDetails.Rows(RowIndex).FindControl("txtUPC"), TextBox)
Dim description As TextBox = TryCast(GridViewDetails.Rows(RowIndex).FindControl("txtDescription"), TextBox)
Dim qty_ordered As TextBox = TryCast(GridViewDetails.Rows(RowIndex).FindControl("txtQtyOrdered"), TextBox)
Dim qty_received As TextBox = TryCast(GridViewDetails.Rows(RowIndex).FindControl("txtQtyReceived"), TextBox)
Dim cost As TextBox = TryCast(GridViewDetails.Rows(RowIndex).FindControl("txtCost"), TextBox)
Dim adjust_amount As TextBox = TryCast(GridViewDetails.Rows(RowIndex).FindControl("txtAdjAmt"), TextBox)
Dim status As DropDownList = TryCast(GridViewDetails.Rows(RowIndex).FindControl("DropListStatusEmpty"), DropDownList)
Dim status_quantity As TextBox = TryCast(GridViewDetails.Rows(RowIndex).FindControl("txtStatusQty"), TextBox)
SourceMisShipDetails.InsertParameters("misship_id").DefaultValue = misship_id.SelectedValue
SourceMisShipDetails.InsertParameters("code_id").DefaultValue = code_id.SelectedValue
SourceMisShipDetails.InsertParameters("upc").DefaultValue = upc.Text
SourceMisShipDetails.InsertParameters("description").DefaultValue = description.Text
SourceMisShipDetails.InsertParameters("qty_ordered").DefaultValue = qty_ordered.Text
SourceMisShipDetails.InsertParameters("qty_received").DefaultValue = qty_received.Text
SourceMisShipDetails.InsertParameters("cost").DefaultValue = cost.Text
SourceMisShipDetails.InsertParameters("adjust_amount").DefaultValue = adjust_amount.Text
SourceMisShipDetails.InsertParameters("status").DefaultValue = status.SelectedValue
SourceMisShipDetails.InsertParameters("status_quantity").DefaultValue = status_quantity.Text
SourceMisShipDetails.Insert()
End Sub